Skip to content

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

Open
BingqingLyu wants to merge 2 commits into
mainfrom
fork-pr-3034-fix-lsp-diagnostics-caching
Open

fix(core): add LSP diagnostics caching and document refresh fallback#85
BingqingLyu wants to merge 2 commits into
mainfrom
fork-pr-3034-fix-lsp-diagnostics-caching

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

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 QwenLM#3029

vadimLuzyanin and others added 2 commits April 9, 2026 01:21
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>
- 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>
@BingqingLyu

BingqingLyu commented May 7, 2026

Copy link
Copy Markdown
Owner Author

Conflict Group 1

This PR shares modified functions with 1 other PR(s): #91.

These PRs should be reviewed as a batch — merging one may affect the others.

Function File Also modified by
doStartServer LspServerManager.ts #91
initializeLspServer LspServerManager.ts #91
graph LR
    PR85["PR #85"]
    FdoStartServer_2706["doStartServer<br>LspServerManager.ts"]
    PR85 -->|modifies| FdoStartServer_2706
    PR91["PR #91"]
    PR91 -->|modifies| FdoStartServer_2706
    FinitializeLspServer_2706["initializeLspServer<br>LspServerManager.ts"]
    PR85 -->|modifies| FinitializeLspServer_2706
    PR91 -->|modifies| FinitializeLspServer_2706
Loading

Posted by codegraph-ai conflict detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicting-group-1 Conflicting PR group 1 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs

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