|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
|
|
|
const START_TIMEOUT_MS = 5_000;
|
|
|
const REQUEST_TIMEOUT_MS = 5_000;
|
|
|
+const DIAGNOSTICS_TIMEOUT_MS = 15_000;
|
|
|
const OPEN_FILE_DELAY_MS = 250;
|
|
|
const INITIALIZE_DELAY_MS = 100;
|
|
|
const DIAGNOSTIC_SETTLE_DELAY_MS = 250;
|
|
|
@@ -28,6 +29,7 @@ const DIAGNOSTIC_SETTLE_DELAY_MS = 250;
|
|
|
export const LSP_TIMEOUTS = {
|
|
|
start: START_TIMEOUT_MS,
|
|
|
request: REQUEST_TIMEOUT_MS,
|
|
|
+ diagnostics: DIAGNOSTICS_TIMEOUT_MS,
|
|
|
openFileDelay: OPEN_FILE_DELAY_MS,
|
|
|
initializeDelay: INITIALIZE_DELAY_MS,
|
|
|
diagnosticSettleDelay: DIAGNOSTIC_SETTLE_DELAY_MS,
|
|
|
@@ -587,7 +589,7 @@ export class LSPClient {
|
|
|
|
|
|
private async waitForPublishedDiagnostics(
|
|
|
uri: string,
|
|
|
- timeoutMs = LSP_TIMEOUTS.request,
|
|
|
+ timeoutMs = LSP_TIMEOUTS.diagnostics,
|
|
|
): Promise<Diagnostic[] | undefined> {
|
|
|
const cachedDiagnostics = this.diagnosticsStore.get(uri);
|
|
|
if (cachedDiagnostics) {
|
|
|
@@ -703,6 +705,7 @@ export class LSPClient {
|
|
|
async diagnostics(filePath: string): Promise<{ items: Diagnostic[] }> {
|
|
|
const absPath = resolve(filePath);
|
|
|
const uri = pathToFileURL(absPath).href;
|
|
|
+ const startedAt = Date.now();
|
|
|
await this.openFile(absPath);
|
|
|
await new Promise((r) => setTimeout(r, LSP_TIMEOUTS.diagnosticSettleDelay));
|
|
|
|
|
|
@@ -725,7 +728,7 @@ export class LSPClient {
|
|
|
textDocument: { uri },
|
|
|
previousResultId: this.diagnosticResultIds.get(uri),
|
|
|
}),
|
|
|
- LSP_TIMEOUTS.request,
|
|
|
+ LSP_TIMEOUTS.diagnostics,
|
|
|
`LSP diagnostics (${this.server.id})`,
|
|
|
)
|
|
|
: undefined;
|
|
|
@@ -761,7 +764,12 @@ export class LSPClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const cachedDiagnostics = await this.waitForPublishedDiagnostics(uri);
|
|
|
+ const elapsed = Date.now() - startedAt;
|
|
|
+ const remainingTimeout = Math.max(LSP_TIMEOUTS.diagnostics - elapsed, 0);
|
|
|
+ const cachedDiagnostics = await this.waitForPublishedDiagnostics(
|
|
|
+ uri,
|
|
|
+ remainingTimeout,
|
|
|
+ );
|
|
|
if (cachedDiagnostics) {
|
|
|
return { items: cachedDiagnostics };
|
|
|
}
|