Skip to content

Fix stale diagnostics when cached results exist#42

Open
mohsenil85 wants to merge 1 commit intoktnyt:mainfrom
mohsenil85:fix/diagnostic-stale-cache
Open

Fix stale diagnostics when cached results exist#42
mohsenil85 wants to merge 1 commit intoktnyt:mainfrom
mohsenil85:fix/diagnostic-stale-cache

Conversation

@mohsenil85
Copy link
Copy Markdown

@mohsenil85 mohsenil85 commented Feb 18, 2026

Summary

  • Fix stale cached diagnostics: When publishDiagnostics results are already cached, getDiagnostics returned them immediately without waiting for rust-analyzer to finish re-analyzing after a file edit. Added a waitForDiagnosticsIdle call in the cached path so in-flight updates settle before returning.
  • Increase default idle detection thresholds: maxWaitTime 1s→2s, idleTime 100→200ms — the previous defaults were too short for multi-crate Rust workspaces.
  • Increase fallback wait times: Fallback paths use multipliers (4-5x) of the base timeout automatically.
  • Make timing configurable: New optional diagnostics field in cclsp.json:
    {
      "diagnostics": {
        "maxWaitMs": 2000,
        "idleMs": 200
      }
    }
    Both fields are optional and default to 2000ms / 200ms respectively.

Context

In a multi-crate Rust workspace (~5 crates), calling get_diagnostics immediately after an edit consistently returned stale results. The root cause was the cached diagnostics fast path (the if (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

  • Tested manually in a 5-crate Rust workspace: introduced a syntax error, called get_diagnostics, confirmed it reported the error
  • Fixed the error, called get_diagnostics again, confirmed the error was gone
  • Previously both calls returned stale results from the prior state

🤖 Generated with Claude Code

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>
@mohsenil85 mohsenil85 force-pushed the fix/diagnostic-stale-cache branch from 4871980 to 59d531e Compare February 18, 2026 18:49
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.

1 participant