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

Publish diagnostics for all open files when multiple files are open #71

Conversation

keyboardDrummer
Copy link
Contributor

@keyboardDrummer keyboardDrummer commented Sep 12, 2018

Notes

  • We now create a debounce function per open file, so two different files will not 'bounce' the diagnostics for one another.
  • I had to use test specific uri's in the tests to prevent the tests from interacting. Even though the tests run in series, they re-use some state (the LSP server) which will causes the tests to interact. Not re-using the state is, I think, not an option because it will slow down the tests.

Testing

  • Ran the tests
  • Tested against an IDE. This CR resolves this issue

@keyboardDrummer keyboardDrummer changed the title Correctly publish diagnostics for all open files when multiple files are open Publish diagnostics for all open files when multiple files are open Sep 12, 2018
}
return result;
fileDiagnostics.updateDiagnostics(kind, event.body.diagnostics).then(this.publishDiagnostics);
Copy link
Contributor

@akosyakov akosyakov Sep 12, 2018

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.

Copy link
Contributor Author

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?

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.

Copy link
Contributor

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);

@akosyakov
Copy link
Contributor

@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.

@keyboardDrummer
Copy link
Contributor Author

keyboardDrummer commented Sep 12, 2018

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).

@akosyakov
Copy link
Contributor

@keyboardDrummer please take care of build failures and let's merge it

@gitpod-io-legacy-app
Copy link

Open in Gitpod - starts a development workspace for this pull request in code review mode and opens it in a browser IDE.

@akosyakov akosyakov merged commit 84824e3 into typescript-language-server:master Sep 13, 2018
@keyboardDrummer keyboardDrummer deleted the typeFoxDiagnosticsFix branch September 13, 2018 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When multiple files are open, only diagnostics from the last accessed file are updated
2 participants