Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with busy spinner showing too many error messages #607

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/LanguageServerManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { LanguageServerManager } from './LanguageServerManager';
import { expect } from 'chai';
import { DefinitionRepository } from './DefinitionRepository';
import { DeclarationProvider } from './DeclarationProvider';
import type { ExtensionContext } from 'vscode';
import type { ExtensionContext, Disposable } from 'vscode';
import * as path from 'path';
import { Deferred, standardizePath as s } from 'brighterscript';
import { BusyStatus, Deferred, standardizePath as s } from 'brighterscript';
import * as fsExtra from 'fs-extra';
import URI from 'vscode-uri';
import { languageServerInfoCommand } from './commands/LanguageServerInfoCommand';
Expand Down Expand Up @@ -525,4 +525,33 @@ describe('LanguageServerManager', () => {
`);
});
});

describe('registerBusyStatusHandler', () => {
it('resets the timer anytime we get a new busy status', async () => {
languageServerManager['busyStatusWarningThreshold'] = 100;

let handler: any;
const client = {
onNotification: (method, h) => {
handler = h;
return undefined as Disposable;
},
outputChannel: {
appendLine: sinon.stub()
}
};
languageServerManager['client'] = client as any;

languageServerManager['registerBusyStatusHandler']();

handler({ status: BusyStatus.busy });
handler({ status: BusyStatus.busy });
handler({ status: BusyStatus.busy });
handler({ status: BusyStatus.busy });

await util.sleep(200);
//we should only have 1 console print (for the final busy event we sent)
expect(client.outputChannel.appendLine.callCount).to.eql(1);
});
});
});
17 changes: 11 additions & 6 deletions src/LanguageServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ export class LanguageServerManager {
return this.ready();
}

/**
* How many milliseconds to wait before showing a warning about the LSP being busy for too long
*/
private busyStatusWarningThreshold = 60_000;

private registerBusyStatusHandler() {
let timeoutHandle: NodeJS.Timeout;

Expand All @@ -287,19 +292,19 @@ export class LanguageServerManager {
console.log(event);
this.updateStatusbar(event.status === BusyStatus.busy, event.activeRuns);

//clear any existing timeout
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}

//if the busy status takes too long, write a lsp log entry with details of what's still pending
if (event.status === BusyStatus.busy) {
timeoutHandle = setTimeout(() => {
const delay = Date.now() - event.timestamp;
this.client.outputChannel.appendLine(`${logger.formatTimestamp(new Date())} language server has been 'busy' for ${delay}ms. most recent busyStatus event: ${JSON.stringify(event, undefined, 4)}`);
}, 60_000);

//clear any existing timeout
} else if (timeoutHandle) {
clearTimeout(timeoutHandle);
}, this.busyStatusWarningThreshold);
}
});

}

/**
Expand Down
Loading