This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Send empty diagnostics when a file is closed
ClosedPublic

Authored by ilya-biryukov on Mar 25 2019, 2:11 AM.

Details

Summary

The LSP clients cannot know clangd will not send diagnostic updates
for closed files, so we send them an empty list of diagnostics to
avoid showing stale diagnostics for closed files in the UI, e.g. in the
"Problems" pane of VSCode.

Fixes PR41217.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Mar 25 2019, 2:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2019, 2:11 AM
hokein added inline comments.Mar 25 2019, 2:23 AM
clang-tools-extra/clangd/ClangdLSPServer.cpp
1000 ↗(On Diff #192057)

IIUC, it seems that we might have race condition here, considering:

  • open a file which will take a long time to get diagnostic
  • the file gets closed, we publish an empty diagnostic
  • we get the diagnostics of the file, and we cache them, and emit them to clients
ilya-biryukov marked an inline comment as done.Mar 25 2019, 2:36 AM
ilya-biryukov added inline comments.
clang-tools-extra/clangd/ClangdLSPServer.cpp
1000 ↗(On Diff #192057)

We should be fine there, TUScheduler won't send diagnostics after the call to remove returns.
This is ensured by calling ASTWorker::stop(), which sets the ASTWorker::ReportDiagnostics flag to false.

hokein accepted this revision.Mar 25 2019, 2:46 AM
hokein added inline comments.
clang-tools-extra/clangd/ClangdLSPServer.cpp
1000 ↗(On Diff #192057)

That makes sense, thanks for the clarification. Maybe add a comment in onDocumentDidClose for future readers.

This revision is now accepted and ready to land.Mar 25 2019, 2:46 AM
ilya-biryukov marked 2 inline comments as done.
  • Added a comment that races are not possible
clang-tools-extra/clangd/ClangdLSPServer.cpp
1000 ↗(On Diff #192057)

Added a comment. Thanks!

This revision was automatically updated to reflect the committed changes.