Fix stale diagnostic error markers in file tree#49333
Fix stale diagnostic error markers in file tree#49333SomeoneToIgnore merged 4 commits intozed-industries:mainfrom
Conversation
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Sorry for coming late, the diagnostics part is relatively hard at places and somehow I failed to express what I found odd in the PR for some time.
#48289 mentions removing files and language server restarts, those parts are covered good in the PR.
The rest, buffer reload and edited, seem a bit out of place, I've left some comments.
Overall, seems that there's indeed some invalidation gist here that needs solving, it's the way to solve it has to be slightly different.
|
Good call @SomeoneToIgnore, I'll hoist (Same pattern exists in You're right, I was trying to handle files not open in any editor that still have stale I'll drop The scenario: user has a file open with diagnostic errors, does "Revert File" (or the file changes externally). If the resulting content is identical to what's in the buffer, Since Instead of clearing summaries directly, I could handle |
|
Thank you, all ideas sounds very reasonable — let's start small and ensure language servers do their part of the job. One small note that a reload scenario is described pretty well, which means we can try and create a test for this use case specifically. |
Diagnostic error markers (red/yellow dots) in the project panel persisted after errors were resolved. Three root causes were identified and fixed: 1. WorktreeUpdatedEntries was ignored in LspStore — when files changed on disk (e.g. after `yarn install`), stale diagnostic summaries were never cleared. Added `invalidate_diagnostic_summaries_for_updated_entries()` to clear summaries for Removed/Updated/AddedOrUpdated paths. 2. stop_local_language_server cleared diagnostic summaries and sent proto messages but never emitted `LspStoreEvent::DiagnosticsUpdated`, so the project panel was never notified to refresh its indicators. 3. Buffer reloads (Revert File, external changes) did not clear stale diagnostic summaries. Added `BufferEvent::Reloaded` handler that clears summaries for the reloaded buffer's path. All three paths also send zeroed `UpdateDiagnosticSummary` proto messages to downstream collab clients. Closes zed-industries#48289
aa8fd4c to
2776853
Compare
|
Applied the requested changes : 1. Hoisted 2. Removed 3. Rewrote 4. Rewrote the buffer reload test with a fake LSP that has workspace diagnostics support, verifying the pull is triggered after reload. One thing to flag: |
There was a problem hiding this comment.
Thank you, I now have mostly style nits and one large question here: it seems more reasonable to update buffer's diagnostics, not the workspace (many buffers) when a single buffer is reloaded?
LspStore has pub fn pull_diagnostics_for_buffer which should suffice for such cases?
Workspace diagnostics refresh can be, again, by the server's request or other, open editors' logic.
That should also help with the notes of the regular buffer's pull prevalence over workspace diagnostics: hopefully the new code structure removes such shenanigans out of this particular test case.
As a downside, we'd be better storing some HashMap<BufferId, Task<()>> and removing that on buffer invalidation — .detach() is bad in this (and many more) cases as we loose the cancellation control.
…simplify - on_buffer_reloaded: use pull_diagnostics_for_buffer (document-level) instead of pull_workspace_diagnostics. Store the task in buffer_reload_tasks HashMap for cancellation control, clean up on buffer invalidation. - Rename invalidate_diagnostic_summaries_for_updated_entries to invalidate_diagnostic_summaries_for_removed_entries. - Replace match with .filter() on PathChange::Removed. - Merge double iteration on summaries_by_server_id into one loop. - Replace .log_err() with .ok() on downstream client send. - Rewrite test to use DocumentDiagnosticRequest (document-level pull).
|
Thanks for the feedback. Here's what changed:
|
…c-markers-file-tree
The upstream commit b9dbc86 causes FakeFs::save to trigger automatic buffer reloads via FS events. Remove the explicit buffer.reload() call — the FS event handles it.
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you, this seems quite clean compared to the original version.
## Summary Fixes zed-industries#48289 Closes zed-industries#52021 Diagnostic error markers (red/yellow dots) in the project panel file tree persisted after errors were resolved. Three root causes: - **WorktreeUpdatedEntries ignored** — when files changed on disk (e.g. `yarn install`), stale diagnostic summaries were never cleared. Added `invalidate_diagnostic_summaries_for_updated_entries()` to clear summaries for `Removed`/`Updated`/`AddedOrUpdated` paths. - **Missing DiagnosticsUpdated emission on server stop** — `stop_local_language_server()` cleared summaries and sent proto messages but never emitted `LspStoreEvent::DiagnosticsUpdated`, so the project panel never refreshed. - **Buffer reload not handled** — reloading a buffer from disk did not clear stale summaries. Added `BufferEvent::Reloaded` handler. All three paths also send zeroed `UpdateDiagnosticSummary` proto messages to downstream collab clients. ## Test plan - [x] `./script/clippy` passes - [x] `cargo test -p project -p project_panel -p worktree` passes (319 tests, 0 failures) - [x] 4 new tests added: - `test_diagnostic_summaries_cleared_on_worktree_entry_removal` - `test_diagnostic_summaries_cleared_on_worktree_entry_update` - `test_diagnostic_summaries_cleared_on_server_restart` - `test_diagnostic_summaries_cleared_on_buffer_reload` - [x] Manual testing: error markers clear when files change on disk - [x] Manual testing: error markers clear on LSP restart Release Notes: - Fixed stale diagnostic data persisting after file reloads, server restarts and FS entry removals
Summary
Fixes #48289
Closes #52021
Diagnostic error markers (red/yellow dots) in the project panel file tree persisted after errors were resolved. Three root causes:
yarn install), stale diagnostic summaries were never cleared. Addedinvalidate_diagnostic_summaries_for_updated_entries()to clear summaries forRemoved/Updated/AddedOrUpdatedpaths.stop_local_language_server()cleared summaries and sent proto messages but never emittedLspStoreEvent::DiagnosticsUpdated, so the project panel never refreshed.BufferEvent::Reloadedhandler.All three paths also send zeroed
UpdateDiagnosticSummaryproto messages to downstream collab clients.Test plan
./script/clippypassescargo test -p project -p project_panel -p worktreepasses (319 tests, 0 failures)test_diagnostic_summaries_cleared_on_worktree_entry_removaltest_diagnostic_summaries_cleared_on_worktree_entry_updatetest_diagnostic_summaries_cleared_on_server_restarttest_diagnostic_summaries_cleared_on_buffer_reloadRelease Notes: