Skip to content

Commit e12fe3f

Browse files
committed
Restart query server when external config changes
This avoids manually restarting the query server when this file changes.
1 parent 36f7555 commit e12fe3f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export type BaseCommands = {
7171
"codeQL.restartQueryServer": () => Promise<void>;
7272
"codeQL.restartQueryServerOnConfigChange": () => Promise<void>;
7373
"codeQL.restartLegacyQueryServerOnConfigChange": () => Promise<void>;
74+
"codeQL.restartQueryServerOnExternalConfigChange": () => Promise<void>;
7475
};
7576

7677
// Commands used when working with queries in the editor

extensions/ql-vscode/src/extension.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { join } from "path";
1919
import { dirSync } from "tmp-promise";
2020
import { testExplorerExtensionId, TestHub } from "vscode-test-adapter-api";
2121
import { lt, parse } from "semver";
22+
import { watch } from "chokidar";
2223

2324
import { AstViewer } from "./astViewer";
2425
import {
@@ -194,6 +195,7 @@ function getCommands(
194195
"codeQL.restartQueryServer": restartQueryServer,
195196
"codeQL.restartQueryServerOnConfigChange": restartQueryServer,
196197
"codeQL.restartLegacyQueryServerOnConfigChange": restartQueryServer,
198+
"codeQL.restartQueryServerOnExternalConfigChange": restartQueryServer,
197199
"codeQL.copyVersion": async () => {
198200
const text = `CodeQL extension version: ${
199201
extension?.packageJSON.version
@@ -672,6 +674,7 @@ async function activateWithInstalledDistribution(
672674
extLogger,
673675
);
674676
ctx.subscriptions.push(cliServer);
677+
watchExternalConfigFile(app, ctx);
675678

676679
const statusBar = new CodeQlStatusBarHandler(
677680
cliServer,
@@ -1010,6 +1013,33 @@ async function activateWithInstalledDistribution(
10101013
};
10111014
}
10121015

1016+
/**
1017+
* Handle changes to the external config file. This is used to restart the query server
1018+
* when the user changes options.
1019+
* See https://docs.github.com/en/code-security/codeql-cli/using-the-codeql-cli/specifying-command-options-in-a-codeql-configuration-file#using-a-codeql-configuration-file
1020+
*/
1021+
function watchExternalConfigFile(app: ExtensionApp, ctx: ExtensionContext) {
1022+
if (process.env.HOME) {
1023+
const configPath = join(process.env.HOME, ".config/codeql", "config");
1024+
const configWatcher = watch(configPath, {
1025+
// These options avoid firing the event twice.
1026+
persistent: true,
1027+
ignoreInitial: true,
1028+
awaitWriteFinish: true,
1029+
});
1030+
configWatcher.on("all", async () => {
1031+
await app.commands.execute(
1032+
"codeQL.restartQueryServerOnExternalConfigChange",
1033+
);
1034+
});
1035+
ctx.subscriptions.push({
1036+
dispose: () => {
1037+
void configWatcher.close();
1038+
},
1039+
});
1040+
}
1041+
}
1042+
10131043
async function showResultsForComparison(
10141044
compareView: CompareView,
10151045
from: CompletedLocalQueryInfo,

0 commit comments

Comments
 (0)