Skip to content

Commit b3ff1ed

Browse files
authored
Merge pull request #2289 from github/aeisenberg/watch-external-config
Restart query server when external config changes
2 parents b5c65b5 + 6de58ec commit b3ff1ed

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fix bug where users could end up with the managed CodeQL CLI getting uninstalled during upgrades and not reinstalled. [#2294](https://github.com/github/vscode-codeql/pull/2294)
88
- Fix bug that was causing code flows to not get updated when switching between results. [#2288](https://github.com/github/vscode-codeql/pull/2288)
99
- Restart the CodeQL language server whenever the _CodeQL: Restart Query Server_ command is invoked. This avoids bugs where the CLI version changes to support new language features, but the language server is not updated. [#2238](https://github.com/github/vscode-codeql/pull/2238)
10+
- Avoid requiring a manual restart of the query server when the [external CLI config file](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) changes. [#2289](https://github.com/github/vscode-codeql/pull/2289)
1011

1112
## 1.8.1 - 23 March 2023
1213

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: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import {
1313
workspace,
1414
} from "vscode";
1515
import { LanguageClient } from "vscode-languageclient/node";
16-
import { arch, platform } from "os";
16+
import { arch, platform, homedir } from "os";
1717
import { ensureDir } from "fs-extra";
1818
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,
@@ -1011,6 +1014,34 @@ async function activateWithInstalledDistribution(
10111014
};
10121015
}
10131016

1017+
/**
1018+
* Handle changes to the external config file. This is used to restart the query server
1019+
* when the user changes options.
1020+
* 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
1021+
*/
1022+
function watchExternalConfigFile(app: ExtensionApp, ctx: ExtensionContext) {
1023+
const home = homedir();
1024+
if (home) {
1025+
const configPath = join(home, ".config", "codeql", "config");
1026+
const configWatcher = watch(configPath, {
1027+
// These options avoid firing the event twice.
1028+
persistent: true,
1029+
ignoreInitial: true,
1030+
awaitWriteFinish: true,
1031+
});
1032+
configWatcher.on("all", async () => {
1033+
await app.commands.execute(
1034+
"codeQL.restartQueryServerOnExternalConfigChange",
1035+
);
1036+
});
1037+
ctx.subscriptions.push({
1038+
dispose: () => {
1039+
void configWatcher.close();
1040+
},
1041+
});
1042+
}
1043+
}
1044+
10141045
async function showResultsForComparison(
10151046
compareView: CompareView,
10161047
from: CompletedLocalQueryInfo,

0 commit comments

Comments
 (0)