Skip to content

Commit 25ae6ed

Browse files
committed
Add command for restarting the query server.
Include a convenience button to show the query server log in case the reason the user wants to restart the server is that it's acting unexpectedly and they want to investigate why.
1 parent ca67d30 commit 25ae6ed

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CodeQL for Visual Studio Code: Changelog
22

3+
## 1.0.6
4+
5+
- Add command to restart query server.
6+
37
## 1.0.5 - 13 February 2020
48

59
- Add an icon next to any failed query runs in the query history

extensions/ql-vscode/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@
206206
{
207207
"command": "codeQLQueryHistory.setLabel",
208208
"title": "Set Label"
209+
},
210+
{
211+
"command": "codeQL.restartQueryServer",
212+
"title": "CodeQL: Restart Query Server"
209213
}
210214
],
211215
"menus": {

extensions/ql-vscode/src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
308308
ctx.subscriptions.push(commands.registerCommand('codeQL.runQuery', async (uri: Uri | undefined) => await compileAndRunQuery(false, uri)));
309309
ctx.subscriptions.push(commands.registerCommand('codeQL.quickEval', async (uri: Uri | undefined) => await compileAndRunQuery(true, uri)));
310310
ctx.subscriptions.push(commands.registerCommand('codeQL.quickQuery', async () => displayQuickQuery(ctx, cliServer, databaseUI)));
311+
ctx.subscriptions.push(commands.registerCommand('codeQL.restartQueryServer', async () => {
312+
await qs.restartQueryServer();
313+
const response = await Window.showInformationMessage('CodeQL Query Server restarted', 'Ok', 'Show Log');
314+
if (response === 'Show Log') {
315+
qs.showLog();
316+
}
317+
}));
311318

312319
ctx.subscriptions.push(client.start());
313320
}

extensions/ql-vscode/src/logging.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export interface Logger {
66
log(message: string): void;
77
/** Writes the given log message, not followed by a newline. */
88
logWithoutTrailingNewline(message: string): void;
9+
/**
10+
* Reveal this channel in the UI.
11+
*
12+
* @param preserveFocus When `true` the channel will not take focus.
13+
*/
14+
show(preserveFocus?: boolean): void;
915
}
1016

1117
export type ProgressReporter = Progress<{ message: string }>;
@@ -28,6 +34,9 @@ export class OutputChannelLogger extends DisposableObject implements Logger {
2834
this.outputChannel.append(message);
2935
}
3036

37+
show(preserveFocus?: boolean) {
38+
this.outputChannel.show(preserveFocus);
39+
}
3140
}
3241

3342
/** The global logger for the extension. */

extensions/ql-vscode/src/queryserver-client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export class QueryServerClient extends DisposableObject {
5656
super();
5757
// When the query server configuration changes, restart the query server.
5858
if (config.onDidChangeQueryServerConfiguration !== undefined) {
59-
this.push(config.onDidChangeQueryServerConfiguration(async () => await this.restartQueryServer(), this));
59+
this.push(config.onDidChangeQueryServerConfiguration(async () => {
60+
this.logger.log('Restarting query server due to configuration changes...');
61+
await this.restartQueryServer();
62+
}, this));
6063
}
6164
this.withProgressReporting = withProgressReporting;
6265
this.nextCallback = 0;
@@ -77,12 +80,15 @@ export class QueryServerClient extends DisposableObject {
7780
}
7881

7982
/** Restarts the query server by disposing of the current server process and then starting a new one. */
80-
private async restartQueryServer() {
81-
this.logger.log('Restarting query server due to configuration changes...');
83+
async restartQueryServer() {
8284
this.stopQueryServer();
8385
await this.startQueryServer();
8486
}
8587

88+
async showLog() {
89+
this.logger.show();
90+
}
91+
8692
/** Starts a new query server process, sending progress messages to the status bar. */
8793
async startQueryServer() {
8894
// Use an arrow function to preserve the value of `this`.

0 commit comments

Comments
 (0)