Skip to content

Commit 71898ac

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 71898ac

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
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`.

extensions/ql-vscode/test/pure-tests/query-test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CancellationTokenSource } from 'vscode-jsonrpc';
1010
import * as messages from '../../src/messages';
1111
import * as qsClient from '../../src/queryserver-client';
1212
import * as cli from '../../src/cli';
13-
import { ProgressReporter } from '../../src/logging';
13+
import { ProgressReporter, Logger } from '../../src/logging';
1414

1515

1616
declare module "url" {
@@ -75,8 +75,8 @@ const queryTestCases: QueryTestCase[] = [
7575
}
7676
];
7777

78-
describe('using the query server', function () {
79-
before(function () {
78+
describe('using the query server', function() {
79+
before(function() {
8080
if (process.env["CODEQL_PATH"] === undefined) {
8181
console.log('The environment variable CODEQL_PATH is not set. The query server tests, which require the CodeQL CLI, will be skipped.');
8282
this.skip();
@@ -100,13 +100,14 @@ describe('using the query server', function () {
100100
}
101101
});
102102

103-
it('should be able to start the query server', async function () {
103+
it('should be able to start the query server', async function() {
104104
const consoleProgressReporter: ProgressReporter = {
105-
report: (v: {message: string}) => console.log(`progress reporter says ${v.message}`)
105+
report: (v: { message: string }) => console.log(`progress reporter says ${v.message}`)
106106
};
107-
const logger = {
107+
const logger: Logger = {
108108
log: (s: string) => console.log('logger says', s),
109-
logWithoutTrailingNewline: (s: string) => console.log('logger says', s)
109+
logWithoutTrailingNewline: (s: string) => console.log('logger says', s),
110+
show: () => { },
110111
};
111112
cliServer = new cli.CodeQLCliServer({
112113
async getCodeQlPathWithoutVersionCheck(): Promise<string | undefined> {
@@ -137,7 +138,7 @@ describe('using the query server', function () {
137138
const evaluationSucceeded = new Checkpoint<void>();
138139
const parsedResults = new Checkpoint<void>();
139140

140-
it(`should be able to compile query ${queryName}`, async function () {
141+
it(`should be able to compile query ${queryName}`, async function() {
141142
await queryServerStarted.done();
142143
expect(fs.existsSync(queryTestCase.queryPath)).to.be.true;
143144
try {
@@ -169,7 +170,7 @@ describe('using the query server', function () {
169170
}
170171
});
171172

172-
it(`should be able to run query ${queryName}`, async function () {
173+
it(`should be able to run query ${queryName}`, async function() {
173174
try {
174175
await compilationSucceeded.done();
175176
const callbackId = qs.registerCallback(_res => {
@@ -201,7 +202,7 @@ describe('using the query server', function () {
201202
});
202203

203204
const actualResultSets: ResultSets = {};
204-
it(`should be able to parse results of query ${queryName}`, async function () {
205+
it(`should be able to parse results of query ${queryName}`, async function() {
205206
let fileReader: FileReader | undefined;
206207
try {
207208
await evaluationSucceeded.done();
@@ -222,7 +223,7 @@ describe('using the query server', function () {
222223
}
223224
});
224225

225-
it(`should have correct results for query ${queryName}`, async function () {
226+
it(`should have correct results for query ${queryName}`, async function() {
226227
await parsedResults.done();
227228
expect(actualResultSets!).not.to.be.empty;
228229
expect(Object.keys(actualResultSets!).sort()).to.eql(Object.keys(queryTestCase.expectedResultSets).sort());

0 commit comments

Comments
 (0)