Skip to content

Commit

Permalink
fix(language-server): if server push diagnostics are not enabled, `pu…
Browse files Browse the repository at this point in the history
…shDiagnostics` should not be notified when a file is closed
  • Loading branch information
johnsoncodehk committed Feb 16, 2024
1 parent a342377 commit a0048bc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/language-server/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export function createServerBase(
updateDiagnostics(document.uri);
});
documents.onDidClose(({ document }) => {
if (!isServerPushEnabled()) {
return;
}
context.connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
});
context.configurationHost?.onDidChangeConfiguration?.(updateDiagnosticsAndSemanticTokens);
Expand Down Expand Up @@ -297,6 +300,9 @@ export function createServerBase(
}

function reloadDiagnostics() {
if (!isServerPushEnabled()) {
return;
}
for (const document of documents.all()) {
context.connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
}
Expand All @@ -319,7 +325,7 @@ export function createServerBase(
if (context.initializeParams.capabilities.workspace?.inlayHint?.refreshSupport) {
context.connection.languages.inlayHint.refresh();
}
if ((context.initializeParams.initializationOptions?.diagnosticModel ?? DiagnosticModel.Push) === DiagnosticModel.Pull) {
if (isServerPushEnabled()) {
if (context.initializeParams.capabilities.workspace?.diagnostics?.refreshSupport) {
context.connection.languages.diagnostics.refresh();
}
Expand All @@ -329,7 +335,7 @@ export function createServerBase(

async function updateDiagnostics(docUri?: string) {

if ((context.initializeParams.initializationOptions?.diagnosticModel ?? DiagnosticModel.Push) !== DiagnosticModel.Push) {
if (!isServerPushEnabled()) {
return;
}

Expand Down Expand Up @@ -370,6 +376,10 @@ export function createServerBase(

context.connection.sendDiagnostics({ uri: uri, diagnostics: errors, version });
}

function isServerPushEnabled() {
return (context.initializeParams.initializationOptions?.diagnosticModel ?? DiagnosticModel.Push) === DiagnosticModel.Push;
}
}

function sleep(ms: number) {
Expand Down

0 comments on commit a0048bc

Please sign in to comment.