Clear stale LSP diagnostics when a file is closed or deleted#4514
Merged
stefanvanburen merged 2 commits intomainfrom Apr 27, 2026
Merged
Clear stale LSP diagnostics when a file is closed or deleted#4514stefanvanburen merged 2 commits intomainfrom
stefanvanburen merged 2 commits intomainfrom
Conversation
Contributor
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
3a319f6 to
2504d03
Compare
When the user closed a file, the LSP server never published empty diagnostics to clear the Problems panel. The root cause is that the workspace's indexFiles path calls fileManager.Track for every file in the module, incrementing the reference count beyond the editor's own reference. When DidClose decrements the count, it rarely drops to zero, so fileManager.Close never calls Reset and diagnostics were never cleared. Fix this by handling the clear explicitly in DidClose: cancel in-flight checks, publish empty diagnostics (while IsOpenInEditor is still true), then set version=-1 to mark the file as no longer open in the editor so subsequent RunChecks skip re-publishing lint diagnostics. Also update Reset to be defensive: publish empty diagnostics if IsOpenInEditor is still true at Reset time (e.g. for workspace-external files whose ref count drops to zero without going through DidClose). Extract the "buf lint" diagnostic source string into a named constant lintSourceName alongside the existing serverName constant. Add a regression test that opens a file with a known lint violation, waits for diagnostics, sends DidClose, then asserts the Problems panel is cleared. Fixes bufbuild/vscode-buf#626.
2504d03 to
386c0e1
Compare
stefanvanburen
commented
Apr 27, 2026
emcfarlane
approved these changes
Apr 27, 2026
doriable
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a file was closed or deleted, the LSP server never published empty diagnostics to clear the client's Problems panel.
Root cause: the workspace's
indexFilespath callsfileManager.Trackfor every file in the module, so the ref count for an editor-open file is typically 2 (one fromDidOpen, one from the workspace). WhenDidClosedecremented the count to 1,Resetwas never called and diagnostics were never cleared.Fix by making
file.ClosecallclearEditorStatebefore decrementing the ref count.clearEditorStatecancels in-flight lint checks, publishes empty diagnostics (only when non-empty, to skip the no-op network write), and setsversion=-1so subsequentRunCheckswon't re-publish lint diagnostics.Also implement
DidDeleteFiles(workspace/didDeleteFiles), previously a NYI stub, so files deleted from disk via the OS or IDE file explorer are handled the same way.Also extract the
"buf lint"diagnostic source string into a named constantlintSourceName.Fixes bufbuild/vscode-buf#626.