Skip to content

Commit e6bd43d

Browse files
Vadim Luzyaninqwencoder
andcommitted
fix(core): address PR review comments on LSP diagnostics fallback
- 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>
1 parent a6315cb commit e6bd43d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/core/src/lsp/LspServerManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ export class LspServerManager {
388388
handle.error = undefined;
389389
handle.warmedUp = false;
390390
handle.stopRequested = false;
391-
handle.cachedDiagnostics?.clear();
392-
handle.pendingDiagnostics?.clear();
391+
handle.cachedDiagnostics.clear();
392+
handle.pendingDiagnostics.clear();
393393
}
394394

395395
private buildProcessEnv(

packages/core/src/lsp/NativeLspService.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ export class NativeLspService {
10661066
);
10671067

10681068
// Force-refresh the document: send didClose + didOpen to trigger fresh analysis
1069+
handle.cachedDiagnostics.delete(uri);
10691070
const openedForServer = this.openedDocuments.get(name);
10701071
if (openedForServer?.has(uri)) {
10711072
openedForServer.delete(uri);
@@ -1092,6 +1093,7 @@ export class NativeLspService {
10921093
},
10931094
});
10941095
await this.delay(DEFAULT_LSP_DOCUMENT_OPEN_DELAY_MS * 5);
1096+
openedForServer.add(uri);
10951097
} catch (err) {
10961098
debugLogger.warn(`Failed to refresh document:`, err);
10971099
openedForServer.add(uri);
@@ -1111,7 +1113,7 @@ export class NativeLspService {
11111113
allDiagnostics.push(normalized2);
11121114
}
11131115
}
1114-
return allDiagnostics;
1116+
continue;
11151117
}
11161118
}
11171119
// Await push diagnostics via pub/sub (Promise.race with 5s timeout)
@@ -1193,9 +1195,13 @@ export class NativeLspService {
11931195
debugLogger.warn(`LSP workspace/diagnostic failed for ${name}:`, error);
11941196

11951197
if (handle.cachedDiagnostics) {
1196-
const workspaceRootUri = pathToFileURL(this.workspaceRoot).toString();
1198+
const workspaceRootUris = this.workspaceContext
1199+
.getDirectories()
1200+
.map((dir) => pathToFileURL(dir).toString());
11971201
for (const [uri, diagnostics] of handle.cachedDiagnostics) {
1198-
if (!uri.startsWith(workspaceRootUri)) continue;
1202+
if (!workspaceRootUris.some((rootUri) => uri.startsWith(rootUri))) {
1203+
continue;
1204+
}
11991205
if (results.length >= limit) break;
12001206
if (diagnostics && diagnostics.length > 0) {
12011207
const normalizedDiagnostics = [];

0 commit comments

Comments
 (0)