Skip to content

Commit c8d64e4

Browse files
authored
Merge branch 'master' into jcreed/more-logging
2 parents 0796893 + 0e4c3be commit c8d64e4

File tree

5 files changed

+150
-27
lines changed

5 files changed

+150
-27
lines changed

extensions/ql-vscode/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ While you can use the [CodeQL CLI to create your own databases](https://help.sem
6666
1. Find a project you're interested in and display the **Integrations** tab (for example, [Apache Kafka](https://lgtm.com/projects/g/apache/kafka/ci/)).
6767
1. Scroll to the **CodeQL databases for local analysis** section at the bottom of the page.
6868
1. Download databases for the languages that you want to explore.
69-
1. Unzip the databases.
7069
1. For each database that you want to import:
71-
1. In the VS Code sidebar, go to **CodeQL** > **Databases** and click **+**.
72-
1. Browse to the unzipped database folder (the parent folder that contains `db-<language>` and `src`) and select **Choose database** to add it.
70+
1. Go to the CodeQL Databases view in the sidebar. Hover over the Databases title bar and click the icon to **Choose Database from Archive**.
71+
1. Browse to the zipped database that you downloaded from LGTM.
7372

74-
When the import is complete, each CodeQL database is displayed in the CodeQL sidebar under **Databases**.
73+
Once you've added a CodeQL database, it is displayed in the Databases view.
7574

7675
### Running a query
7776

extensions/ql-vscode/package.json

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
"onView:codeQLQueryHistory",
2828
"onView:test-explorer",
2929
"onCommand:codeQL.checkForUpdatesToCLI",
30+
"onCommand:codeQLDatabases.chooseDatabaseFolder",
31+
"onCommand:codeQLDatabases.chooseDatabaseArchive",
32+
"onCommand:codeQLDatabases.chooseDatabaseInternet",
33+
"onCommand:codeQL.setCurrentDatabase",
3034
"onCommand:codeQL.chooseDatabaseFolder",
3135
"onCommand:codeQL.chooseDatabaseArchive",
3236
"onCommand:codeQL.chooseDatabaseInternet",
33-
"onCommand:codeQL.setCurrentDatabase",
34-
"onCommand:codeQL.downloadDatabase",
3537
"onCommand:codeQLDatabases.chooseDatabase",
3638
"onCommand:codeQLDatabases.setCurrentDatabase",
3739
"onCommand:codeQL.quickQuery",
@@ -175,24 +177,24 @@
175177
"title": "CodeQL: Quick Query"
176178
},
177179
{
178-
"command": "codeQL.chooseDatabaseFolder",
180+
"command": "codeQLDatabases.chooseDatabaseFolder",
179181
"title": "Choose Database from Folder",
180182
"icon": {
181183
"light": "media/light/folder-opened-plus.svg",
182184
"dark": "media/dark/folder-opened-plus.svg"
183185
}
184186
},
185187
{
186-
"command": "codeQL.chooseDatabaseArchive",
188+
"command": "codeQLDatabases.chooseDatabaseArchive",
187189
"title": "Choose Database from Archive",
188190
"icon": {
189191
"light": "media/light/archive-plus.svg",
190192
"dark": "media/dark/archive-plus.svg"
191193
}
192194
},
193195
{
194-
"command": "codeQL.chooseDatabaseInternet",
195-
"title": "Download database",
196+
"command": "codeQLDatabases.chooseDatabaseInternet",
197+
"title": "Download Database",
196198
"icon": {
197199
"light": "media/light/cloud-download.svg",
198200
"dark": "media/dark/cloud-download.svg"
@@ -231,8 +233,16 @@
231233
"title": "Show Database Directory"
232234
},
233235
{
234-
"command": "codeQL.downloadDatabase",
235-
"title": "CodeQL: Download database"
236+
"command": "codeQL.chooseDatabaseFolder",
237+
"title": "CodeQL: Choose Database from Folder"
238+
},
239+
{
240+
"command": "codeQL.chooseDatabaseArchive",
241+
"title": "CodeQL: Choose Database from Archive"
242+
},
243+
{
244+
"command": "codeQL.chooseDatabaseInternet",
245+
"title": "CodeQL: Download Database"
236246
},
237247
{
238248
"command": "codeQLDatabases.sortByName",
@@ -312,17 +322,17 @@
312322
"group": "navigation"
313323
},
314324
{
315-
"command": "codeQL.chooseDatabaseFolder",
325+
"command": "codeQLDatabases.chooseDatabaseFolder",
316326
"when": "view == codeQLDatabases",
317327
"group": "navigation"
318328
},
319329
{
320-
"command": "codeQL.chooseDatabaseArchive",
330+
"command": "codeQLDatabases.chooseDatabaseArchive",
321331
"when": "view == codeQLDatabases",
322332
"group": "navigation"
323333
},
324334
{
325-
"command": "codeQL.chooseDatabaseInternet",
335+
"command": "codeQLDatabases.chooseDatabaseInternet",
326336
"when": "view == codeQLDatabases",
327337
"group": "navigation"
328338
}
@@ -406,10 +416,6 @@
406416
"command": "codeQL.runQuery",
407417
"when": "resourceLangId == ql && resourceExtname == .ql"
408418
},
409-
{
410-
"command": "codeQL.downloadDatabase",
411-
"when": "true"
412-
},
413419
{
414420
"command": "codeQL.quickEval",
415421
"when": "editorLangId == ql"
@@ -442,6 +448,22 @@
442448
"command": "codeQLDatabases.removeDatabase",
443449
"when": "false"
444450
},
451+
{
452+
"command": "codeQLDatabases.chooseDatabaseFolder",
453+
"when": "false"
454+
},
455+
{
456+
"command": "codeQLDatabases.chooseDatabaseArchive",
457+
"when": "false"
458+
},
459+
{
460+
"command": "codeQLDatabases.chooseDatabaseInternet",
461+
"when": "false"
462+
},
463+
{
464+
"command": "codeQLDatabases.upgradeDatabase",
465+
"when": "false"
466+
},
445467
{
446468
"command": "codeQLQueryHistory.openQuery",
447469
"when": "false"

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ export class DatabaseUI extends DisposableObject {
175175
this.push(window.createTreeView('codeQLDatabases', { treeDataProvider: this.treeDataProvider }));
176176

177177
logger.log('Registering database panel commands.');
178-
ctx.subscriptions.push(commands.registerCommand('codeQL.chooseDatabaseFolder', this.handleChooseDatabaseFolder));
179-
ctx.subscriptions.push(commands.registerCommand('codeQL.chooseDatabaseArchive', this.handleChooseDatabaseArchive));
180-
ctx.subscriptions.push(commands.registerCommand('codeQL.chooseDatabaseInternet', this.handleChooseDatabaseInternet));
178+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.chooseDatabaseFolder', this.handleChooseDatabaseFolder));
179+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.chooseDatabaseArchive', this.handleChooseDatabaseArchive));
180+
ctx.subscriptions.push(commands.registerCommand('codeQLDatabases.chooseDatabaseInternet', this.handleChooseDatabaseInternet));
181181
ctx.subscriptions.push(commands.registerCommand('codeQL.setCurrentDatabase', this.handleSetCurrentDatabase));
182182
ctx.subscriptions.push(commands.registerCommand('codeQL.upgradeCurrentDatabase', this.handleUpgradeCurrentDatabase));
183183
ctx.subscriptions.push(commands.registerCommand('codeQL.clearCache', this.handleClearCache));
@@ -194,7 +194,7 @@ export class DatabaseUI extends DisposableObject {
194194
await this.databaseManager.setCurrentDatabaseItem(databaseItem);
195195
}
196196

197-
private handleChooseDatabaseFolder = async (): Promise<DatabaseItem | undefined> => {
197+
handleChooseDatabaseFolder = async (): Promise<DatabaseItem | undefined> => {
198198
try {
199199
return await this.chooseAndSetDatabase(true);
200200
} catch (e) {
@@ -203,7 +203,7 @@ export class DatabaseUI extends DisposableObject {
203203
}
204204
}
205205

206-
private handleChooseDatabaseArchive = async (): Promise<DatabaseItem | undefined> => {
206+
handleChooseDatabaseArchive = async (): Promise<DatabaseItem | undefined> => {
207207
try {
208208
return await this.chooseAndSetDatabase(false);
209209
} catch (e) {
@@ -212,7 +212,7 @@ export class DatabaseUI extends DisposableObject {
212212
}
213213
}
214214

215-
private handleChooseDatabaseInternet = async (): Promise<DatabaseItem | undefined> => {
215+
handleChooseDatabaseInternet = async (): Promise<DatabaseItem | undefined> => {
216216
return await promptImportInternetDatabase(this.databaseManager, this.storagePath);
217217
}
218218

extensions/ql-vscode/src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { displayQuickQuery } from './quick-query';
2020
import { compileAndRunQueryAgainstDatabase, tmpDirDisposal, UserCancellationException } from './run-queries';
2121
import { QLTestAdapterFactory } from './test-adapter';
2222
import { TestUIService } from './test-ui';
23-
import { promptImportInternetDatabase } from './databaseFetcher';
2423

2524
/**
2625
* extension.ts
@@ -346,7 +345,9 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
346345
await qs.restartQueryServer();
347346
helpers.showAndLogInformationMessage('CodeQL Query Server restarted.', { outputLogger: queryServerLogger });
348347
}));
349-
ctx.subscriptions.push(commands.registerCommand('codeQL.downloadDatabase', () => promptImportInternetDatabase(dbm, getContextStoragePath(ctx))));
348+
ctx.subscriptions.push(commands.registerCommand('codeQL.chooseDatabaseFolder', () => databaseUI.handleChooseDatabaseFolder()));
349+
ctx.subscriptions.push(commands.registerCommand('codeQL.chooseDatabaseArchive', () => databaseUI.handleChooseDatabaseArchive()));
350+
ctx.subscriptions.push(commands.registerCommand('codeQL.chooseDatabaseInternet', () => databaseUI.handleChooseDatabaseInternet()));
350351

351352
logger.log('Starting language server.');
352353
ctx.subscriptions.push(client.start());
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { expect } from 'chai';
2+
import * as path from 'path';
3+
import * as fs from 'fs-extra';
4+
5+
type CmdDecl = {
6+
command: string;
7+
when?: string;
8+
title?: string;
9+
}
10+
11+
describe('commands declared in package.json', function() {
12+
const manifest = fs.readJsonSync(path.join(__dirname, '../../package.json'));
13+
const commands = manifest.contributes.commands;
14+
const menus = manifest.contributes.menus;
15+
16+
const disabledInPalette: Set<string> = new Set<string>();
17+
18+
// These commands should appear in the command palette, and so
19+
// should be prefixed with 'CodeQL: '.
20+
const paletteCmds: Set<string> = new Set<string>();
21+
22+
// These commands arising on context menus in non-CodeQL controlled
23+
// panels, (e.g. file browser) and so should be prefixed with 'CodeQL: '.
24+
const contribContextMenuCmds: Set<string> = new Set<string>();
25+
26+
// These are commands used in CodeQL controlled panels, and so don't need any prefixing in their title.
27+
const scopedCmds: Set<string> = new Set<string>();
28+
const commandTitles: { [cmd: string]: string } = {};
29+
30+
commands.forEach((commandDecl: CmdDecl) => {
31+
const { command, title } = commandDecl;
32+
if (command.match(/^codeQL\./)
33+
|| command.match(/^codeQLQueryResults\./)
34+
|| command.match(/^codeQLTests\./)) {
35+
paletteCmds.add(command);
36+
expect(title).not.to.be.undefined;
37+
commandTitles[command] = title!;
38+
}
39+
else if (command.match(/^codeQLDatabases\./)
40+
|| command.match(/^codeQLQueryHistory\./)) {
41+
scopedCmds.add(command);
42+
expect(title).not.to.be.undefined;
43+
commandTitles[command] = title!;
44+
}
45+
else {
46+
expect.fail(`Unexpected command name ${command}`);
47+
}
48+
});
49+
50+
menus['explorer/context'].forEach((commandDecl: CmdDecl) => {
51+
const { command } = commandDecl;
52+
paletteCmds.delete(command);
53+
contribContextMenuCmds.add(command);
54+
});
55+
56+
menus['editor/context'].forEach((commandDecl: CmdDecl) => {
57+
const { command } = commandDecl;
58+
paletteCmds.delete(command);
59+
contribContextMenuCmds.add(command);
60+
});
61+
62+
menus.commandPalette.forEach((commandDecl: CmdDecl) => {
63+
if (commandDecl.when === 'false')
64+
disabledInPalette.add(commandDecl.command);
65+
});
66+
67+
68+
69+
it('should have commands appropriately prefixed', function() {
70+
paletteCmds.forEach(command => {
71+
expect(commandTitles[command], `command ${command} should be prefixed with 'CodeQL: ', since it is accessible from the command palette`).to.match(/^CodeQL: /);
72+
});
73+
74+
contribContextMenuCmds.forEach(command => {
75+
expect(commandTitles[command], `command ${command} should be prefixed with 'CodeQL: ', since it is accessible from a context menu in a non-extension-controlled context`).to.match(/^CodeQL: /);
76+
});
77+
78+
scopedCmds.forEach(command => {
79+
expect(commandTitles[command], `command ${command} should not be prefixed with 'CodeQL: ', since it is accessible from an extension-controlled context`).not.to.match(/^CodeQL: /);
80+
});
81+
});
82+
83+
it('should have the right commands accessible from the command palette', function() {
84+
paletteCmds.forEach(command => {
85+
expect(disabledInPalette.has(command), `command ${command} should be enabled in the command palette`).to.be.false;
86+
});
87+
88+
// Commands in contribContextMenuCmds may reasonbly be enabled or
89+
// disabled in the command palette; for example, codeQL.runQuery
90+
// is available there, since we heuristically figure out which
91+
// query to run, but codeQL.setCurrentDatabase is not.
92+
93+
scopedCmds.forEach(command => {
94+
expect(disabledInPalette.has(command), `command ${command} should be disabled in the command palette`).to.be.true;
95+
});
96+
});
97+
98+
99+
});
100+
101+

0 commit comments

Comments
 (0)