Skip to content

Commit 51e8897

Browse files
committed
Give visibility information to the ide-server.
This allows it to report errors on visible files eagerly.
1 parent 9a3a96b commit 51e8897

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,17 @@ async function activateWithInstalledDistribution(
10131013
void ideServer.stop();
10141014
},
10151015
});
1016+
1017+
// Handle visibility changes in the ideserver
1018+
if (await cliServer.cliConstraints.supportsVisibilityNotifications()) {
1019+
Window.onDidChangeVisibleTextEditors((editors) => {
1020+
ideServer.notifyVisibilityChange(editors);
1021+
});
1022+
// Send an inital notification to the language server
1023+
// to set the initial state of the visible editors.
1024+
ideServer.notifyVisibilityChange(Window.visibleTextEditors);
1025+
}
1026+
10161027
// Jump-to-definition and find-references
10171028
void extLogger.log("Registering jump-to-definition handlers.");
10181029

extensions/ql-vscode/src/language-support/ide-server.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { ProgressLocation, window } from "vscode";
2-
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
1+
import { ProgressLocation, TextEditor, window } from "vscode";
2+
import {
3+
LanguageClient,
4+
NotificationType,
5+
StreamInfo,
6+
} from "vscode-languageclient/node";
37
import { shouldDebugIdeServer, spawnServer } from "../codeql-cli/cli";
48
import { QueryServerConfig } from "../config";
59
import { ideServerLogger } from "../common";
@@ -41,6 +45,15 @@ export class CodeQLLanguageClient extends LanguageClient {
4145
true,
4246
);
4347
}
48+
49+
notifyVisibilityChange(editors: readonly TextEditor[]) {
50+
const files = editors
51+
.filter((e) => e.document.uri.scheme === "file")
52+
.map((e) => e.document.uri.toString());
53+
void this.sendNotification(didChangeVisibileFiles, {
54+
visibleFiles: files,
55+
});
56+
}
4457
}
4558

4659
/** Starts a new CodeQL language server process, sending progress messages to the status bar. */
@@ -70,3 +83,13 @@ async function spawnIdeServer(config: QueryServerConfig): Promise<StreamInfo> {
7083
},
7184
);
7285
}
86+
87+
/**
88+
* Custom notification type for when the set of visible files changes.
89+
*/
90+
interface DidChangeVisibileFilesParams {
91+
visibleFiles: string[];
92+
}
93+
94+
const didChangeVisibileFiles: NotificationType<DidChangeVisibileFilesParams> =
95+
new NotificationType("textDocument/codeQLDidChangeVisibleFiles");

0 commit comments

Comments
 (0)