Skip to content

fix(core): add LSP diagnostics caching and document refresh fallback#3034

Open
vadimLuzyanin wants to merge 2 commits intoQwenLM:mainfrom
vadimLuzyanin:fix-lsp-diagnostics-caching
Open

fix(core): add LSP diagnostics caching and document refresh fallback#3034
vadimLuzyanin wants to merge 2 commits intoQwenLM:mainfrom
vadimLuzyanin:fix-lsp-diagnostics-caching

Conversation

@vadimLuzyanin
Copy link
Copy Markdown

TLDR

Fixes missing LSP diagnostics by caching textDocument/publishDiagnostics notifications and using them as a fallback when textDocument/diagnostic pull requests fail. Also adds document refresh (didClose + didOpen) to trigger fresh analysis from the LSP server.

Screenshots / Video Demo

N/A — internal change, verified end-to-end: the fixed build reports all TypeScript diagnostics while the original build returns none. Full flow confirmed in a single session: diagnose → fix → re-diagnose.

Dive Deeper

The LSP textDocument/diagnostic pull request fails on some LSP servers (e.g., typescript-language-server in certain configurations), leaving users with no diagnostics. This change adds a push-based fallback: LspServerManager now listens to publishDiagnostics notifications from the server and caches them. When the pull fails, NativeLspService force-refreshes the document (didClose + didOpen) and reads from the cache, with a 5s timeout via Promise.race. The same cache is also used as a fallback for workspaceDiagnostics when workspace/diagnostic fails, filtered by workspace root URI.

Reviewer Test Plan

Create a TypeScript file with intentional type errors in a workspace with .lsp.json configured for typescript-language-server. Run with --experimental-lsp and ask for diagnostics — should report all errors. Add another error to the file and ask again — should include the new error. Then ask the CLI to fix the errors and re-check diagnostics — should report zero remaining.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #3029

Add publishDiagnostics notification handler in LspServerManager that
caches diagnostics and supports pending diagnostic promises. When
textDocument/diagnostic pull fails in NativeLspService, fall back to
force-refreshing the document (didClose + didOpen) and reading from
the cached diagnostics.

Also fix review findings:
- Clear cache/pending maps on server restart in resetHandle()
- Clean up pending diagnostics entries on timeout
- Re-track URI in openedDocuments on refresh failure
- Filter workspaceDiagnostics fallback by workspace root URI

Fixes QwenLM#3029

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@vadimLuzyanin vadimLuzyanin force-pushed the fix-lsp-diagnostics-caching branch 2 times, most recently from 4a09091 to a6315cb Compare April 9, 2026 23:35
- Clear stale cache entry before refresh (not after) to prevent
  wiping fresh publishDiagnostics data that arrives during the delay
- Re-add URI to openedDocuments after successful didOpen to keep
  local tracking in sync
- Use continue instead of return to aggregate diagnostics from all
  servers in multi-server setups
- Filter workspaceDiagnostics fallback by all workspace root URIs
  from WorkspaceContext for multi-root workspace support

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
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.

LSP workspaceDiagnostics and diagnostics return empty for typescript-language-server

2 participants