Skip to content

Commit dbdab13

Browse files
author
Dave Bartolomeo
authored
Merge pull request #2291 from github/dbartol/debug-adapter
Implement basic CodeQL debug adapter
2 parents 02f1482 + a151ade commit dbdab13

27 files changed

+2461
-252
lines changed

extensions/ql-vscode/package-lock.json

Lines changed: 31 additions & 0 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: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,48 @@
7676
"editor.wordBasedSuggestions": false
7777
}
7878
},
79+
"debuggers": [
80+
{
81+
"type": "codeql",
82+
"label": "CodeQL Debugger",
83+
"languages": [
84+
"ql"
85+
],
86+
"configurationAttributes": {
87+
"launch": {
88+
"properties": {
89+
"query": {
90+
"type": "string",
91+
"description": "Path to query file (.ql)",
92+
"default": "${file}"
93+
},
94+
"database": {
95+
"type": "string",
96+
"description": "Path to the target database"
97+
},
98+
"additionalPacks": {
99+
"type": [
100+
"array",
101+
"string"
102+
],
103+
"description": "Additional folders to search for library packs. Defaults to searching all workspace folders."
104+
},
105+
"extensionPacks": {
106+
"type": [
107+
"array",
108+
"string"
109+
],
110+
"description": "Names of extension packs to include in the evaluation. These are resolved from the locations specified in `additionalPacks`."
111+
}
112+
}
113+
}
114+
},
115+
"variables": {
116+
"currentDatabase": "codeQL.getCurrentDatabase",
117+
"currentQuery": "codeQL.getCurrentQuery"
118+
}
119+
}
120+
],
79121
"jsonValidation": [
80122
{
81123
"fileMatch": "GitHub.vscode-codeql/databases.json",
@@ -314,6 +356,30 @@
314356
"command": "codeQL.runQueryContextEditor",
315357
"title": "CodeQL: Run Query on Selected Database"
316358
},
359+
{
360+
"command": "codeQL.debugQuery",
361+
"title": "CodeQL: Debug Query"
362+
},
363+
{
364+
"command": "codeQL.debugQueryContextEditor",
365+
"title": "CodeQL: Debug Query"
366+
},
367+
{
368+
"command": "codeQL.startDebuggingSelection",
369+
"title": "CodeQL: Debug Selection"
370+
},
371+
{
372+
"command": "codeQL.startDebuggingSelectionContextEditor",
373+
"title": "CodeQL: Debug Selection"
374+
},
375+
{
376+
"command": "codeQL.continueDebuggingSelection",
377+
"title": "CodeQL: Debug Selection"
378+
},
379+
{
380+
"command": "codeQL.continueDebuggingSelectionContextEditor",
381+
"title": "CodeQL: Debug Selection"
382+
},
317383
{
318384
"command": "codeQL.runQueryOnMultipleDatabases",
319385
"title": "CodeQL: Run Query on Multiple Databases"
@@ -453,6 +519,14 @@
453519
"command": "codeQL.setCurrentDatabase",
454520
"title": "CodeQL: Set Current Database"
455521
},
522+
{
523+
"command": "codeQL.getCurrentDatabase",
524+
"title": "CodeQL: Get Current Database"
525+
},
526+
{
527+
"command": "codeQL.getCurrentQuery",
528+
"title": "CodeQL: Get Current Query"
529+
},
456530
{
457531
"command": "codeQL.viewAst",
458532
"title": "CodeQL: View AST"
@@ -1038,6 +1112,30 @@
10381112
"command": "codeQL.runQueryContextEditor",
10391113
"when": "false"
10401114
},
1115+
{
1116+
"command": "codeQL.debugQuery",
1117+
"when": "config.codeQL.canary && editorLangId == ql && resourceExtname == .ql && !inDebugMode"
1118+
},
1119+
{
1120+
"command": "codeQL.debugQueryContextEditor",
1121+
"when": "false"
1122+
},
1123+
{
1124+
"command": "codeQL.startDebuggingSelection",
1125+
"when": "config.codeQL.canary && editorLangId == ql && debugState == inactive && debugConfigurationType == codeql"
1126+
},
1127+
{
1128+
"command": "codeQL.startDebuggingSelectionContextEditor",
1129+
"when": "false"
1130+
},
1131+
{
1132+
"command": "codeQL.continueDebuggingSelection",
1133+
"when": "config.codeQL.canary && editorLangId == ql && debugState == stopped && debugType == codeql"
1134+
},
1135+
{
1136+
"command": "codeQL.continueDebuggingSelectionContextEditor",
1137+
"when": "false"
1138+
},
10411139
{
10421140
"command": "codeQL.runQueryOnMultipleDatabases",
10431141
"when": "resourceLangId == ql && resourceExtname == .ql"
@@ -1086,6 +1184,14 @@
10861184
"command": "codeQL.setCurrentDatabase",
10871185
"when": "false"
10881186
},
1187+
{
1188+
"command": "codeQL.getCurrentDatabase",
1189+
"when": "false"
1190+
},
1191+
{
1192+
"command": "codeQL.getCurrentQuery",
1193+
"when": "false"
1194+
},
10891195
{
10901196
"command": "codeQL.viewAst",
10911197
"when": "resourceScheme == codeql-zip-archive"
@@ -1350,7 +1456,7 @@
13501456
"editor/context": [
13511457
{
13521458
"command": "codeQL.runQueryContextEditor",
1353-
"when": "editorLangId == ql && resourceExtname == .ql"
1459+
"when": "editorLangId == ql && resourceExtname == .ql && !inDebugMode"
13541460
},
13551461
{
13561462
"command": "codeQL.runQueryOnMultipleDatabasesContextEditor",
@@ -1370,7 +1476,19 @@
13701476
},
13711477
{
13721478
"command": "codeQL.quickEvalContextEditor",
1373-
"when": "editorLangId == ql"
1479+
"when": "editorLangId == ql && debugState == inactive"
1480+
},
1481+
{
1482+
"command": "codeQL.debugQueryContextEditor",
1483+
"when": "config.codeQL.canary && editorLangId == ql && resourceExtname == .ql && !inDebugMode"
1484+
},
1485+
{
1486+
"command": "codeQL.startDebuggingSelectionContextEditor",
1487+
"when": "config.codeQL.canary && editorLangId == ql && debugState == inactive && debugConfigurationType == codeql"
1488+
},
1489+
{
1490+
"command": "codeQL.continueDebuggingSelectionContextEditor",
1491+
"when": "config.codeQL.canary && editorLangId == ql && debugState == stopped && debugType == codeql"
13741492
},
13751493
{
13761494
"command": "codeQL.openReferencedFileContextEditor",
@@ -1471,6 +1589,8 @@
14711589
"@octokit/plugin-retry": "^3.0.9",
14721590
"@octokit/rest": "^19.0.4",
14731591
"@vscode/codicons": "^0.0.31",
1592+
"@vscode/debugadapter": "^1.59.0",
1593+
"@vscode/debugprotocol": "^1.59.0",
14741594
"@vscode/webview-ui-toolkit": "^1.0.1",
14751595
"ajv": "^8.11.0",
14761596
"child-process-promise": "^2.2.1",

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
VariantAnalysisScannedRepository,
1212
VariantAnalysisScannedRepositoryResult,
1313
} from "../variant-analysis/shared/variant-analysis";
14+
import type { QLDebugConfiguration } from "../debugger/debug-configuration";
1415

1516
// A command function matching the signature that VS Code calls when
1617
// a command is invoked from the title bar of a TreeView with
@@ -87,6 +88,15 @@ export type BuiltInVsCodeCommands = {
8788
) => Promise<void>;
8889
"vscode.open": (uri: Uri) => Promise<void>;
8990
"vscode.openFolder": (uri: Uri) => Promise<void>;
91+
// We type the `config` property specifically as a CodeQL debug configuration, since that's the
92+
// only kinds we specify anyway.
93+
"workbench.action.debug.start": (options?: {
94+
config?: Partial<QLDebugConfiguration>;
95+
noDebug?: boolean;
96+
}) => Promise<void>;
97+
"workbench.action.debug.stepInto": () => Promise<void>;
98+
"workbench.action.debug.stepOver": () => Promise<void>;
99+
"workbench.action.debug.stepOut": () => Promise<void>;
90100
};
91101

92102
// Commands that are available before the extension is fully activated.
@@ -134,9 +144,20 @@ export type LocalQueryCommands = {
134144
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
135145
"codeQL.codeLensQuickEval": (uri: Uri, range: Range) => Promise<void>;
136146
"codeQL.quickQuery": () => Promise<void>;
147+
"codeQL.getCurrentQuery": () => Promise<string>;
137148
"codeQL.createQuery": () => Promise<void>;
138149
};
139150

151+
// Debugger commands
152+
export type DebuggerCommands = {
153+
"codeQL.debugQuery": (uri: Uri | undefined) => Promise<void>;
154+
"codeQL.debugQueryContextEditor": (uri: Uri) => Promise<void>;
155+
"codeQL.startDebuggingSelection": () => Promise<void>;
156+
"codeQL.startDebuggingSelectionContextEditor": () => Promise<void>;
157+
"codeQL.continueDebuggingSelection": () => Promise<void>;
158+
"codeQL.continueDebuggingSelectionContextEditor": () => Promise<void>;
159+
};
160+
140161
export type ResultsViewCommands = {
141162
"codeQLQueryResults.up": () => Promise<void>;
142163
"codeQLQueryResults.down": () => Promise<void>;
@@ -219,6 +240,7 @@ export type LocalDatabasesCommands = {
219240

220241
// Internal commands
221242
"codeQLDatabases.removeOrphanedDatabases": () => Promise<void>;
243+
"codeQL.getCurrentDatabase": () => Promise<string | undefined>;
222244
};
223245

224246
// Commands tied to variant analysis
@@ -317,6 +339,7 @@ export type AllExtensionCommands = BaseCommands &
317339
ResultsViewCommands &
318340
QueryHistoryCommands &
319341
LocalDatabasesCommands &
342+
DebuggerCommands &
320343
VariantAnalysisCommands &
321344
DatabasePanelCommands &
322345
AstCfgCommands &

0 commit comments

Comments
 (0)