-
Notifications
You must be signed in to change notification settings - Fork 156
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
Publish diagnostics for all open files when multiple files are open #71
Publish diagnostics for all open files when multiple files are open #71
Conversation
server/src/diagnostic-queue.ts
Outdated
} | ||
return result; | ||
fileDiagnostics.updateDiagnostics(kind, event.body.diagnostics).then(this.publishDiagnostics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't it execute publishDiagnostics
as many times as updateDiagnostics
is called instead of once? How about passing publishDiagnostics
to FileDiagnostics
and using firePublishDiagnostics
as it was before, i.e. without any async logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't it execute
publishDiagnostics
as many times asupdateDiagnostics
is called instead of once?
It won't. If you look at updateDiagnostics
, you can see it only resolves the promise once if multiple calls happen within the debounce window, since the call to resolve
is within the function passed to debounce
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, although the code will be less tricky (without any async handling) on impl and client sides:
constructor(
readonly uri: string,
protected publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void
) { }
updateDiagnostics(kind: EventTypes, diagnostics: tsp.Diagnostic[]): void {
this.diagnosticsPerKind.set(kind, diagnostics.map(toDiagnostic));
this.firePublishDiagnostics();
}
protected firePublishDiagnostics = debounce((): void => {
const { uri } = this;
const diagnostics = this.getDiagnostics();
this.publishDiagnostics({ uri, diagnostics });
}, 50);
@keyboardDrummer Goot catch! Before it will postpone publishing diagnostics for all files while tsserver is spamming with diagnostic events, e.g. during the full build on a monorepo. With this change, diagnostics debounced only for a single file leading to republishing a lot of unnecessary diagnostics in some cases. I would prefer that we debounce for all files as before, but fix an issue with publishing only for last. |
The current implementation will publish diagnostics for all open files whenever diagnostics change, this allows IDE's to implement something like a problems view, where diagnostics are shown not just for the last edited file but for multiple files. If you look at the problems view in VS Code you will see that it shows errors for all open files (for TypeScript). |
@keyboardDrummer please take care of build failures and let's merge it |
Open in Gitpod - starts a development workspace for this pull request in code review mode and opens it in a browser IDE. |
Notes
debounce
function per open file, so two different files will not 'bounce' the diagnostics for one another.Testing