Skip to content

Commit 3826e35

Browse files
authored
Merge branch 'main' into aeisenberg/cli-version-telemetry
2 parents 0da40a6 + 8e40d7d commit 3826e35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5343
-1201
lines changed

extensions/ql-vscode/package-lock.json

Lines changed: 3957 additions & 508 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
"title": "CodeQL: Quick Query"
363363
},
364364
{
365-
"command": "codeQL.createSkeletonQuery",
365+
"command": "codeQL.createQuery",
366366
"title": "CodeQL: Create Query"
367367
},
368368
{
@@ -1321,6 +1321,10 @@
13211321
{
13221322
"command": "codeQL.mockGitHubApiServer.unloadScenario",
13231323
"when": "config.codeQL.mockGitHubApiServer.enabled && codeQL.mockGitHubApiServer.scenarioLoaded"
1324+
},
1325+
{
1326+
"command": "codeQL.createQuery",
1327+
"when": "config.codeQL.canary"
13241328
}
13251329
],
13261330
"editor/context": [
@@ -1493,7 +1497,7 @@
14931497
"@storybook/addon-essentials": "^6.5.17-alpha.0",
14941498
"@storybook/addon-interactions": "^6.5.17-alpha.0",
14951499
"@storybook/addon-links": "^6.5.17-alpha.0",
1496-
"@storybook/builder-webpack5": "^6.5.17-alpha.0",
1500+
"@storybook/builder-webpack5": "^7.0.4",
14971501
"@storybook/manager-webpack5": "^6.5.17-alpha.0",
14981502
"@storybook/react": "^6.5.17-alpha.0",
14991503
"@storybook/testing-library": "^0.0.13",

extensions/ql-vscode/src/cli.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ export type MlModelInfo = {
107107
/** The expected output of `codeql resolve ml-models`. */
108108
export type MlModelsInfo = { models: MlModelInfo[] };
109109

110+
/** Information about a data extension predicate, as resolved by `codeql resolve extensions`. */
111+
export type DataExtensionResult = {
112+
predicate: string;
113+
file: string;
114+
index: number;
115+
};
116+
117+
/** The expected output of `codeql resolve extensions`. */
118+
export type ResolveExtensionsResult = {
119+
models: MlModelInfo[];
120+
data: {
121+
[path: string]: DataExtensionResult[];
122+
};
123+
};
124+
110125
/**
111126
* The expected output of `codeql resolve qlref`.
112127
*/
@@ -1196,6 +1211,29 @@ export class CodeQLCliServer implements Disposable {
11961211
);
11971212
}
11981213

1214+
/**
1215+
* Gets information about available extensions
1216+
* @param suite The suite to resolve.
1217+
* @param additionalPacks A list of directories to search for qlpacks.
1218+
* @returns An object containing the list of models and extensions
1219+
*/
1220+
async resolveExtensions(
1221+
suite: string,
1222+
additionalPacks: string[],
1223+
): Promise<ResolveExtensionsResult> {
1224+
const args = this.getAdditionalPacksArg(additionalPacks);
1225+
args.push(suite);
1226+
1227+
return this.runJsonCodeQlCliCommand<ResolveExtensionsResult>(
1228+
["resolve", "extensions"],
1229+
args,
1230+
"Resolving extensions",
1231+
{
1232+
addFormat: false,
1233+
},
1234+
);
1235+
}
1236+
11991237
/**
12001238
* Gets information about the available languages.
12011239
* @returns A dictionary mapping language name to the directory it comes from

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

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,53 @@ import type {
1313
} from "../variant-analysis/shared/variant-analysis";
1414

1515
// A command function matching the signature that VS Code calls when
16-
// a command on a selection is invoked.
17-
export type SelectionCommandFunction<Item> = (
16+
// a command is invoked from the title bar of a TreeView with
17+
// canSelectMany set to true.
18+
//
19+
// It is possible to get any combination of singleItem and multiSelect
20+
// to be undefined. This is because it is possible to click a title bar
21+
// option without interacting with any individual items first, or even
22+
// when there are no items present at all.
23+
// If both singleItem and multiSelect are defined, then singleItem will
24+
// be contained within multiSelect.
25+
export type TreeViewTitleMultiSelectionCommandFunction<Item> = (
26+
singleItem: Item | undefined,
27+
multiSelect: Item[] | undefined,
28+
) => Promise<void>;
29+
30+
// A command function matching the signature that VS Code calls when
31+
// a command is invoked from a context menu on a TreeView with
32+
// canSelectMany set to true.
33+
//
34+
// singleItem will always be defined and corresponds to the item that
35+
// was hovered or right-clicked. If precisely one item was selected then
36+
// multiSelect will be undefined. If more than one item is selected then
37+
// multiSelect will contain all selected items, including singleItem.
38+
export type TreeViewContextMultiSelectionCommandFunction<Item> = (
1839
singleItem: Item,
19-
multiSelect: Item[],
40+
multiSelect: Item[] | undefined,
2041
) => Promise<void>;
2142

2243
// A command function matching the signature that VS Code calls when
23-
// a command on a selection is invoked when canSelectMany is false.
24-
export type SingleSelectionCommandFunction<Item> = (
44+
// a command is invoked from a context menu on a TreeView with
45+
// canSelectMany set to false.
46+
//
47+
// It is guaranteed that precisely one item will be selected.
48+
export type TreeViewContextSingleSelectionCommandFunction<Item> = (
2549
singleItem: Item,
2650
) => Promise<void>;
2751

52+
// A command function matching the signature that VS Code calls when
53+
// a command is invoked from a context menu on the file explorer.
54+
//
55+
// singleItem corresponds to the item that was right-clicked.
56+
// multiSelect will always been defined and non-empty and contains
57+
// all selected items, including singleItem.
58+
export type ExplorerSelectionCommandFunction<Item> = (
59+
singleItem: Item,
60+
multiSelect: Item[],
61+
) => Promise<void>;
62+
2863
/**
2964
* Contains type definitions for all commands used by the extension.
3065
*
@@ -94,12 +129,12 @@ export type LocalQueryCommands = {
94129
"codeQL.runQueryOnMultipleDatabasesContextEditor": (
95130
uri?: Uri,
96131
) => Promise<void>;
97-
"codeQL.runQueries": SelectionCommandFunction<Uri>;
132+
"codeQL.runQueries": ExplorerSelectionCommandFunction<Uri>;
98133
"codeQL.quickEval": (uri: Uri) => Promise<void>;
99134
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
100135
"codeQL.codeLensQuickEval": (uri: Uri, range: Range) => Promise<void>;
101136
"codeQL.quickQuery": () => Promise<void>;
102-
"codeQL.createSkeletonQuery": () => Promise<void>;
137+
"codeQL.createQuery": () => Promise<void>;
103138
};
104139

105140
export type ResultsViewCommands = {
@@ -119,28 +154,28 @@ export type QueryHistoryCommands = {
119154
"codeQLQueryHistory.sortByCount": () => Promise<void>;
120155

121156
// Commands in the context menu or in the hover menu
122-
"codeQLQueryHistory.openQueryTitleMenu": SelectionCommandFunction<QueryHistoryInfo>;
123-
"codeQLQueryHistory.openQueryContextMenu": SelectionCommandFunction<QueryHistoryInfo>;
124-
"codeQLQueryHistory.removeHistoryItemTitleMenu": SelectionCommandFunction<QueryHistoryInfo>;
125-
"codeQLQueryHistory.removeHistoryItemContextMenu": SelectionCommandFunction<QueryHistoryInfo>;
126-
"codeQLQueryHistory.removeHistoryItemContextInline": SelectionCommandFunction<QueryHistoryInfo>;
127-
"codeQLQueryHistory.renameItem": SelectionCommandFunction<QueryHistoryInfo>;
128-
"codeQLQueryHistory.compareWith": SelectionCommandFunction<QueryHistoryInfo>;
129-
"codeQLQueryHistory.showEvalLog": SelectionCommandFunction<QueryHistoryInfo>;
130-
"codeQLQueryHistory.showEvalLogSummary": SelectionCommandFunction<QueryHistoryInfo>;
131-
"codeQLQueryHistory.showEvalLogViewer": SelectionCommandFunction<QueryHistoryInfo>;
132-
"codeQLQueryHistory.showQueryLog": SelectionCommandFunction<QueryHistoryInfo>;
133-
"codeQLQueryHistory.showQueryText": SelectionCommandFunction<QueryHistoryInfo>;
134-
"codeQLQueryHistory.openQueryDirectory": SelectionCommandFunction<QueryHistoryInfo>;
135-
"codeQLQueryHistory.cancel": SelectionCommandFunction<QueryHistoryInfo>;
136-
"codeQLQueryHistory.exportResults": SelectionCommandFunction<QueryHistoryInfo>;
137-
"codeQLQueryHistory.viewCsvResults": SelectionCommandFunction<QueryHistoryInfo>;
138-
"codeQLQueryHistory.viewCsvAlerts": SelectionCommandFunction<QueryHistoryInfo>;
139-
"codeQLQueryHistory.viewSarifAlerts": SelectionCommandFunction<QueryHistoryInfo>;
140-
"codeQLQueryHistory.viewDil": SelectionCommandFunction<QueryHistoryInfo>;
141-
"codeQLQueryHistory.itemClicked": SelectionCommandFunction<QueryHistoryInfo>;
142-
"codeQLQueryHistory.openOnGithub": SelectionCommandFunction<QueryHistoryInfo>;
143-
"codeQLQueryHistory.copyRepoList": SelectionCommandFunction<QueryHistoryInfo>;
157+
"codeQLQueryHistory.openQueryTitleMenu": TreeViewTitleMultiSelectionCommandFunction<QueryHistoryInfo>;
158+
"codeQLQueryHistory.openQueryContextMenu": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
159+
"codeQLQueryHistory.removeHistoryItemTitleMenu": TreeViewTitleMultiSelectionCommandFunction<QueryHistoryInfo>;
160+
"codeQLQueryHistory.removeHistoryItemContextMenu": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
161+
"codeQLQueryHistory.removeHistoryItemContextInline": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
162+
"codeQLQueryHistory.renameItem": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
163+
"codeQLQueryHistory.compareWith": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
164+
"codeQLQueryHistory.showEvalLog": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
165+
"codeQLQueryHistory.showEvalLogSummary": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
166+
"codeQLQueryHistory.showEvalLogViewer": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
167+
"codeQLQueryHistory.showQueryLog": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
168+
"codeQLQueryHistory.showQueryText": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
169+
"codeQLQueryHistory.openQueryDirectory": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
170+
"codeQLQueryHistory.cancel": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
171+
"codeQLQueryHistory.exportResults": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
172+
"codeQLQueryHistory.viewCsvResults": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
173+
"codeQLQueryHistory.viewCsvAlerts": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
174+
"codeQLQueryHistory.viewSarifAlerts": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
175+
"codeQLQueryHistory.viewDil": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
176+
"codeQLQueryHistory.itemClicked": TreeViewTitleMultiSelectionCommandFunction<QueryHistoryInfo>;
177+
"codeQLQueryHistory.openOnGithub": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
178+
"codeQLQueryHistory.copyRepoList": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
144179

145180
// Commands in the command palette
146181
"codeQL.exportSelectedVariantAnalysisResults": () => Promise<void>;
@@ -173,11 +208,11 @@ export type LocalDatabasesCommands = {
173208
) => Promise<void>;
174209

175210
// Database panel selection commands
176-
"codeQLDatabases.removeDatabase": SelectionCommandFunction<DatabaseItem>;
177-
"codeQLDatabases.upgradeDatabase": SelectionCommandFunction<DatabaseItem>;
178-
"codeQLDatabases.renameDatabase": SelectionCommandFunction<DatabaseItem>;
179-
"codeQLDatabases.openDatabaseFolder": SelectionCommandFunction<DatabaseItem>;
180-
"codeQLDatabases.addDatabaseSource": SelectionCommandFunction<DatabaseItem>;
211+
"codeQLDatabases.removeDatabase": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
212+
"codeQLDatabases.upgradeDatabase": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
213+
"codeQLDatabases.renameDatabase": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
214+
"codeQLDatabases.openDatabaseFolder": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
215+
"codeQLDatabases.addDatabaseSource": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
181216

182217
// Codespace template commands
183218
"codeQL.setDefaultTourDatabase": () => Promise<void>;
@@ -222,11 +257,11 @@ export type DatabasePanelCommands = {
222257
"codeQLVariantAnalysisRepositories.addNewList": () => Promise<void>;
223258
"codeQLVariantAnalysisRepositories.setupControllerRepository": () => Promise<void>;
224259

225-
"codeQLVariantAnalysisRepositories.setSelectedItem": SingleSelectionCommandFunction<DbTreeViewItem>;
226-
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
227-
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
228-
"codeQLVariantAnalysisRepositories.renameItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
229-
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
260+
"codeQLVariantAnalysisRepositories.setSelectedItem": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
261+
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
262+
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
263+
"codeQLVariantAnalysisRepositories.renameItemContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
264+
"codeQLVariantAnalysisRepositories.removeItemContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
230265
};
231266

232267
export type AstCfgCommands = {

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-module.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { ensureDir } from "fs-extra";
88
import { join } from "path";
99
import { App } from "../common/app";
1010
import { showAndLogErrorMessage } from "../helpers";
11+
import { withProgress } from "../progress";
12+
import { pickExtensionPackModelFile } from "./extension-pack-picker";
1113

1214
export class DataExtensionsEditorModule {
1315
private readonly queryStorageDir: string;
@@ -49,31 +51,46 @@ export class DataExtensionsEditorModule {
4951

5052
public getCommands(): DataExtensionsEditorCommands {
5153
return {
52-
"codeQL.openDataExtensionsEditor": async () => {
53-
const db = this.databaseManager.currentDatabaseItem;
54-
if (!db) {
55-
void showAndLogErrorMessage("No database selected");
56-
return;
57-
}
54+
"codeQL.openDataExtensionsEditor": async () =>
55+
withProgress(
56+
async (progress) => {
57+
const db = this.databaseManager.currentDatabaseItem;
58+
if (!db) {
59+
void showAndLogErrorMessage("No database selected");
60+
return;
61+
}
5862

59-
if (!(await this.cliServer.cliConstraints.supportsQlpacksKind())) {
60-
void showAndLogErrorMessage(
61-
`This feature requires CodeQL CLI version ${CliVersionConstraint.CLI_VERSION_WITH_QLPACKS_KIND.format()} or later.`,
62-
);
63-
return;
64-
}
63+
if (!(await this.cliServer.cliConstraints.supportsQlpacksKind())) {
64+
void showAndLogErrorMessage(
65+
`This feature requires CodeQL CLI version ${CliVersionConstraint.CLI_VERSION_WITH_QLPACKS_KIND.format()} or later.`,
66+
);
67+
return;
68+
}
6569

66-
const view = new DataExtensionsEditorView(
67-
this.ctx,
68-
this.app,
69-
this.databaseManager,
70-
this.cliServer,
71-
this.queryRunner,
72-
this.queryStorageDir,
73-
db,
74-
);
75-
await view.openView();
76-
},
70+
const modelFile = await pickExtensionPackModelFile(
71+
this.cliServer,
72+
progress,
73+
);
74+
if (!modelFile) {
75+
return;
76+
}
77+
78+
const view = new DataExtensionsEditorView(
79+
this.ctx,
80+
this.app,
81+
this.databaseManager,
82+
this.cliServer,
83+
this.queryRunner,
84+
this.queryStorageDir,
85+
db,
86+
modelFile,
87+
);
88+
await view.openView();
89+
},
90+
{
91+
title: "Opening Data Extensions Editor",
92+
},
93+
),
7794
};
7895
}
7996

0 commit comments

Comments
 (0)