Fix stale diagnostics when cached results exist#42
Open
mohsenil85 wants to merge 1 commit intoktnyt:mainfrom
Open
Fix stale diagnostics when cached results exist#42mohsenil85 wants to merge 1 commit intoktnyt:mainfrom
mohsenil85 wants to merge 1 commit intoktnyt:mainfrom
Conversation
When diagnostics are already cached from publishDiagnostics, getDiagnostics
returns them immediately without waiting for rust-analyzer to finish
re-analyzing after a file edit. This causes stale results in multi-crate
Rust workspaces where re-analysis takes significant time.
Changes:
- Add waitForDiagnosticsIdle call in the cached diagnostics path so
in-flight updates settle before returning
- Increase default wait parameters (maxWaitTime 1s→2s, idleTime 100→200ms)
- Increase fallback wait times for multi-crate workspaces
- Make diagnostic timing configurable via cclsp.json:
```json
{
"diagnostics": {
"maxWaitMs": 2000,
"idleMs": 200
}
}
```
Fallback paths use multipliers (4-5x) of the base values automatically.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4871980 to
59d531e
Compare
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.
Summary
publishDiagnosticsresults are already cached,getDiagnosticsreturned them immediately without waiting for rust-analyzer to finish re-analyzing after a file edit. Added awaitForDiagnosticsIdlecall in the cached path so in-flight updates settle before returning.maxWaitTime1s→2s,idleTime100→200ms — the previous defaults were too short for multi-crate Rust workspaces.diagnosticsfield incclsp.json:{ "diagnostics": { "maxWaitMs": 2000, "idleMs": 200 } }Context
In a multi-crate Rust workspace (~5 crates), calling
get_diagnosticsimmediately after an edit consistently returned stale results. The root cause was the cached diagnostics fast path (theif (cachedDiagnostics !== undefined)branch), which returned instantly. The fallback paths with their waits were never reached because diagnostics from a previous analysis were already cached.Test plan
get_diagnostics, confirmed it reported the errorget_diagnosticsagain, confirmed the error was gone🤖 Generated with Claude Code