forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.ts
386 lines (348 loc) · 17.3 KB
/
commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
import type { CommandManager } from "../packages/commands";
import type { Uri, Range, TextDocumentShowOptions, TestItem } from "vscode";
import type { AstItem } from "../language-support";
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
import type { DatabaseItem } from "../databases/local-databases";
import type { QueryHistoryInfo } from "../query-history/query-history-info";
import type {
VariantAnalysis,
VariantAnalysisScannedRepository,
VariantAnalysisScannedRepositoryResult,
} from "../variant-analysis/shared/variant-analysis";
import type { QLDebugConfiguration } from "../debugger/debug-configuration";
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
import type { LanguageSelectionTreeViewItem } from "../language-selection-panel/language-selection-data-provider";
import type { Method, Usage } from "../model-editor/method";
// A command function matching the signature that VS Code calls when
// a command is invoked from a context menu on a TreeView with
// canSelectMany set to true.
//
// singleItem will always be defined and corresponds to the item that
// was hovered or right-clicked. If precisely one item was selected then
// multiSelect will be undefined. If more than one item is selected then
// multiSelect will contain all selected items, including singleItem.
export type TreeViewContextMultiSelectionCommandFunction<Item> = (
singleItem: Item,
multiSelect: Item[] | undefined,
) => Promise<void>;
// A command function matching the signature that VS Code calls when
// a command is invoked from a context menu on a TreeView with
// canSelectMany set to false.
//
// It is guaranteed that precisely one item will be selected.
export type TreeViewContextSingleSelectionCommandFunction<Item> = (
singleItem: Item,
) => Promise<void>;
// A command function matching the signature that VS Code calls when
// a command is invoked from a context menu on the file explorer.
//
// singleItem corresponds to the item that was right-clicked.
// multiSelect will always been defined and non-empty and contains
// all selected items, including singleItem.
export type ExplorerSelectionCommandFunction<Item> = (
singleItem: Item,
multiSelect: Item[],
) => Promise<void>;
/**
* Contains type definitions for all commands used by the extension.
*
* To add a new command first define its type here, then provide
* the implementation in the corresponding `getCommands` function.
*/
// Builtin commands where the implementation is provided by VS Code and not by this extension.
// See https://code.visualstudio.com/api/references/commands
type BuiltInVsCodeCommands = {
// The codeQLDatabases.focus command is provided by VS Code because we've registered the custom view
"codeQLDatabases.focus": () => Promise<void>;
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
"workbench.action.closeActiveEditor": () => Promise<void>;
revealFileInOS: (uri: Uri) => Promise<void>;
setContext: (
key: `${"codeql" | "codeQL"}${string}`,
value: unknown,
) => Promise<void>;
"workbench.action.reloadWindow": () => Promise<void>;
"vscode.diff": (
leftSideResource: Uri,
rightSideResource: Uri,
title?: string,
columnOrOptions?: TextDocumentShowOptions,
) => Promise<void>;
"vscode.open": (uri: Uri) => Promise<void>;
"vscode.openFolder": (uri: Uri) => Promise<void>;
revealInExplorer: (uri: Uri) => Promise<void>;
// We type the `config` property specifically as a CodeQL debug configuration, since that's the
// only kinds we specify anyway.
"workbench.action.debug.start": (options?: {
config?: Partial<QLDebugConfiguration>;
noDebug?: boolean;
}) => Promise<void>;
"workbench.action.debug.stepInto": () => Promise<void>;
"workbench.action.debug.stepOver": () => Promise<void>;
"workbench.action.debug.stepOut": () => Promise<void>;
};
// Commands that are available before the extension is fully activated.
// These commands are *not* registered using the command manager, but can
// be invoked using the command manager.
export type PreActivationCommands = {
"codeQL.checkForUpdatesToCLI": () => Promise<void>;
};
// Base commands not tied directly to a module like e.g. variant analysis.
export type BaseCommands = {
"codeQL.openDocumentation": () => Promise<void>;
"codeQL.showLogs": () => Promise<void>;
"codeQL.authenticateToGitHub": () => Promise<void>;
"codeQL.copyVersion": () => Promise<void>;
"codeQL.restartQueryServer": () => Promise<void>;
"codeQL.restartQueryServerOnConfigChange": () => Promise<void>;
"codeQL.restartLegacyQueryServerOnConfigChange": () => Promise<void>;
"codeQL.restartQueryServerOnExternalConfigChange": () => Promise<void>;
};
// Commands used when working with queries in the editor
export type QueryEditorCommands = {
"codeQL.openReferencedFile": (selectedQuery: Uri) => Promise<void>;
"codeQL.openReferencedFileContextEditor": (
selectedQuery: Uri,
) => Promise<void>;
"codeQL.openReferencedFileContextExplorer": (
selectedQuery: Uri,
) => Promise<void>;
"codeQL.previewQueryHelp": (selectedQuery: Uri) => Promise<void>;
"codeQL.previewQueryHelpContextEditor": (selectedQuery: Uri) => Promise<void>;
"codeQL.previewQueryHelpContextExplorer": (
selectedQuery: Uri,
) => Promise<void>;
};
// Commands used for running local queries
export type LocalQueryCommands = {
"codeQL.runQuery": (uri?: Uri) => Promise<void>;
"codeQL.runQueryContextEditor": (uri?: Uri) => Promise<void>;
"codeQL.runQueryOnMultipleDatabases": (uri?: Uri) => Promise<void>;
"codeQL.runQueryOnMultipleDatabasesContextEditor": (
uri?: Uri,
) => Promise<void>;
"codeQLQueries.runLocalQueryFromQueriesPanel": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
"codeQLQueries.runLocalQueryContextMenu": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
"codeQLQueries.runLocalQueriesContextMenu": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
"codeQLQueries.runLocalQueriesFromPanel": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
"codeQLQueries.createQuery": () => Promise<void>;
"codeQL.runLocalQueryFromFileTab": (uri: Uri) => Promise<void>;
"codeQL.runQueries": ExplorerSelectionCommandFunction<Uri>;
"codeQL.quickEval": (uri: Uri) => Promise<void>;
"codeQL.quickEvalCount": (uri: Uri) => Promise<void>;
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
"codeQL.codeLensQuickEval": (uri: Uri, range: Range) => Promise<void>;
"codeQL.quickQuery": () => Promise<void>;
"codeQL.getCurrentQuery": () => Promise<string>;
"codeQL.createQuery": () => Promise<void>;
"codeQLQuickQuery.createQuery": () => Promise<void>;
};
// Debugger commands
export type DebuggerCommands = {
"codeQL.debugQuery": (uri: Uri | undefined) => Promise<void>;
"codeQL.debugQueryContextEditor": (uri: Uri) => Promise<void>;
"codeQL.startDebuggingSelection": () => Promise<void>;
"codeQL.startDebuggingSelectionContextEditor": () => Promise<void>;
"codeQL.continueDebuggingSelection": () => Promise<void>;
"codeQL.continueDebuggingSelectionContextEditor": () => Promise<void>;
};
export type ResultsViewCommands = {
"codeQLQueryResults.up": () => Promise<void>;
"codeQLQueryResults.down": () => Promise<void>;
"codeQLQueryResults.left": () => Promise<void>;
"codeQLQueryResults.right": () => Promise<void>;
"codeQLQueryResults.nextPathStep": () => Promise<void>;
"codeQLQueryResults.previousPathStep": () => Promise<void>;
};
// Commands used for the query history panel
export type QueryHistoryCommands = {
// Commands in the "navigation" group
"codeQLQueryHistory.sortByName": () => Promise<void>;
"codeQLQueryHistory.sortByDate": () => Promise<void>;
"codeQLQueryHistory.sortByCount": () => Promise<void>;
// Commands in the context menu or in the hover menu
"codeQLQueryHistory.openQueryContextMenu": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.removeHistoryItemContextMenu": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.removeHistoryItemContextInline": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.renameItem": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.compareWith": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.comparePerformanceWith": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.showEvalLog": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.showEvalLogSummary": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.showEvalLogViewer": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.showQueryLog": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.showQueryText": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.openQueryDirectory": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.cancel": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.exportResults": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.viewCsvResults": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.viewCsvAlerts": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.viewSarifAlerts": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.viewDil": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.itemClicked": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.openOnGithub": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.copyRepoList": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
// Commands in the command palette
"codeQL.exportSelectedVariantAnalysisResults": () => Promise<void>;
};
// Commands user for the language selector panel
export type LanguageSelectionCommands = {
"codeQLLanguageSelection.setSelectedItem": (
item: LanguageSelectionTreeViewItem,
) => Promise<void>;
};
// Commands used for the local databases panel
export type LocalDatabasesCommands = {
// Command palette commands
"codeQL.chooseDatabaseFolder": () => Promise<void>;
"codeQL.chooseDatabaseFoldersParent": () => Promise<void>;
"codeQL.chooseDatabaseArchive": () => Promise<void>;
"codeQL.chooseDatabaseInternet": () => Promise<void>;
"codeQL.chooseDatabaseGithub": () => Promise<void>;
"codeQL.upgradeCurrentDatabase": () => Promise<void>;
"codeQL.clearCache": () => Promise<void>;
"codeQL.trimCache": () => Promise<void>;
// Explorer context menu
"codeQL.setCurrentDatabase": (uri: Uri) => Promise<void>;
"codeQL.importTestDatabase": (uri: Uri) => Promise<void>;
// Database panel view title commands
"codeQLDatabases.chooseDatabaseFolder": () => Promise<void>;
"codeQLDatabases.chooseDatabaseArchive": () => Promise<void>;
"codeQLDatabases.chooseDatabaseInternet": () => Promise<void>;
"codeQLDatabases.chooseDatabaseGithub": () => Promise<void>;
"codeQLDatabases.sortByName": () => Promise<void>;
"codeQLDatabases.sortByLanguage": () => Promise<void>;
"codeQLDatabases.sortByDateAdded": () => Promise<void>;
// Database panel context menu
"codeQLDatabases.setCurrentDatabase": (
databaseItem: DatabaseItem,
) => Promise<void>;
// Database panel selection commands
"codeQLDatabases.removeDatabase": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
"codeQLDatabases.upgradeDatabase": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
"codeQLDatabases.renameDatabase": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
"codeQLDatabases.openDatabaseFolder": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
"codeQLDatabases.addDatabaseSource": TreeViewContextMultiSelectionCommandFunction<DatabaseItem>;
// Codespace template commands
"codeQL.setDefaultTourDatabase": () => Promise<void>;
// Internal commands
"codeQLDatabases.removeOrphanedDatabases": () => Promise<void>;
"codeQL.getCurrentDatabase": () => Promise<string | undefined>;
};
// Commands tied to variant analysis
export type VariantAnalysisCommands = {
"codeQL.autoDownloadVariantAnalysisResult": (
scannedRepo: VariantAnalysisScannedRepository,
variantAnalysisSummary: VariantAnalysis,
) => Promise<void>;
"codeQL.loadVariantAnalysisRepoResults": (
variantAnalysisId: number,
repositoryFullName: string,
) => Promise<VariantAnalysisScannedRepositoryResult>;
"codeQL.monitorNewVariantAnalysis": (
variantAnalysis: VariantAnalysis,
) => Promise<void>;
"codeQL.monitorRehydratedVariantAnalysis": (
variantAnalysis: VariantAnalysis,
) => Promise<void>;
"codeQL.monitorReauthenticatedVariantAnalysis": (
variantAnalysis: VariantAnalysis,
) => Promise<void>;
"codeQL.openVariantAnalysisLogs": (
variantAnalysisId: number,
) => Promise<void>;
"codeQLModelAlerts.openVariantAnalysisLogs": (
variantAnalysisId: number,
) => Promise<void>;
"codeQL.openVariantAnalysisView": (
variantAnalysisId: number,
) => Promise<void>;
"codeQL.runVariantAnalysis": () => Promise<void>;
"codeQL.runVariantAnalysisContextEditor": (uri: Uri) => Promise<void>;
"codeQL.runVariantAnalysisContextExplorer": ExplorerSelectionCommandFunction<Uri>;
"codeQLQueries.runVariantAnalysisContextMenu": TreeViewContextSingleSelectionCommandFunction<QueryTreeViewItem>;
"codeQL.runVariantAnalysisPublishedPack": () => Promise<void>;
};
export type DatabasePanelCommands = {
"codeQLVariantAnalysisRepositories.openConfigFile": () => Promise<void>;
"codeQLVariantAnalysisRepositories.addNewDatabase": () => Promise<void>;
"codeQLVariantAnalysisRepositories.addNewList": () => Promise<void>;
"codeQLVariantAnalysisRepositories.setupControllerRepository": () => Promise<void>;
"codeQLVariantAnalysisRepositories.setSelectedItem": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
"codeQLVariantAnalysisRepositories.openOnGitHubContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
"codeQLVariantAnalysisRepositories.renameItemContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
"codeQLVariantAnalysisRepositories.removeItemContextMenu": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
"codeQLVariantAnalysisRepositories.importFromCodeSearch": TreeViewContextSingleSelectionCommandFunction<DbTreeViewItem>;
};
export type AstCfgCommands = {
"codeQL.viewAst": (selectedFile: Uri) => Promise<void>;
"codeQL.viewAstContextExplorer": (selectedFile: Uri) => Promise<void>;
"codeQL.viewAstContextEditor": (selectedFile: Uri) => Promise<void>;
"codeQL.viewCfg": () => Promise<void>;
"codeQL.viewCfgContextExplorer": () => Promise<void>;
"codeQL.viewCfgContextEditor": () => Promise<void>;
};
export type AstViewerCommands = {
"codeQLAstViewer.clear": () => Promise<void>;
"codeQLAstViewer.gotoCode": (item: AstItem) => Promise<void>;
};
export type PackagingCommands = {
"codeQL.installPackDependencies": () => Promise<void>;
"codeQL.downloadPacks": () => Promise<void>;
};
export type ModelEditorCommands = {
"codeQL.openModelEditor": () => Promise<void>;
"codeQL.openModelEditorFromModelingPanel": () => Promise<void>;
"codeQLModelEditor.jumpToMethod": (
method: Method,
usage: Usage,
databaseItem: DatabaseItem,
) => Promise<void>;
};
export type EvalLogViewerCommands = {
"codeQLEvalLogViewer.clear": () => Promise<void>;
};
export type SummaryLanguageSupportCommands = {
"codeQL.gotoQL": () => Promise<void>;
"codeQL.gotoQLContextEditor": () => Promise<void>;
};
export type TestUICommands = {
"codeQLTests.showOutputDifferences": (node: TestItem) => Promise<void>;
"codeQLTests.acceptOutput": (node: TestItem) => Promise<void>;
"codeQLTests.acceptOutputContextTestItem": (node: TestItem) => Promise<void>;
};
export type MockGitHubApiServerCommands = {
"codeQL.mockGitHubApiServer.startRecording": () => Promise<void>;
"codeQL.mockGitHubApiServer.saveScenario": () => Promise<void>;
"codeQL.mockGitHubApiServer.cancelRecording": () => Promise<void>;
"codeQL.mockGitHubApiServer.loadScenario": (
scenario?: string,
) => Promise<void>;
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
};
// All commands where the implementation is provided by this activated extension.
export type AllExtensionCommands = BaseCommands &
QueryEditorCommands &
ResultsViewCommands &
QueryHistoryCommands &
LanguageSelectionCommands &
LocalDatabasesCommands &
DebuggerCommands &
VariantAnalysisCommands &
DatabasePanelCommands &
AstCfgCommands &
AstViewerCommands &
PackagingCommands &
ModelEditorCommands &
EvalLogViewerCommands &
SummaryLanguageSupportCommands &
Partial<TestUICommands> &
MockGitHubApiServerCommands;
export type AllCommands = AllExtensionCommands &
PreActivationCommands &
BuiltInVsCodeCommands;
export type AppCommandManager = CommandManager<AllCommands>;
// Separate command manager because it uses a different logger
export type QueryServerCommands = LocalQueryCommands;
export type QueryServerCommandManager = CommandManager<QueryServerCommands>;