Skip to content

Commit d489d0e

Browse files
author
Dave Bartolomeo
committed
QuickEval
1 parent 65b0cb4 commit d489d0e

12 files changed

Lines changed: 554 additions & 187 deletions

extensions/ql-vscode/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@
494494
"command": "codeQL.getCurrentQuery",
495495
"title": "CodeQL: Get Current Query"
496496
},
497+
{
498+
"command": "codeQL.debug.quickEval",
499+
"title": "CodeQL Debugger: Quick Evaluation"
500+
},
501+
{
502+
"command": "codeQL.debug.quickEvalContextEditor",
503+
"title": "CodeQL Debugger: Quick Evaluation"
504+
},
497505
{
498506
"command": "codeQL.viewAst",
499507
"title": "CodeQL: View AST"
@@ -1092,6 +1100,14 @@
10921100
"command": "codeQL.quickEvalContextEditor",
10931101
"when": "false"
10941102
},
1103+
{
1104+
"command": "codeQL.debug.quickEval",
1105+
"when": "config.codeQL.canary && editorLangId == ql"
1106+
},
1107+
{
1108+
"command": "codeQL.debug.quickEvalContextEditor",
1109+
"when": "false"
1110+
},
10951111
{
10961112
"command": "codeQL.openReferencedFile",
10971113
"when": "resourceExtname == .qlref"
@@ -1394,6 +1410,10 @@
13941410
"command": "codeQL.quickEvalContextEditor",
13951411
"when": "editorLangId == ql"
13961412
},
1413+
{
1414+
"command": "codeQL.debug.quickEvalContextEditor",
1415+
"when": "config.codeQL.canary && editorLangId == ql"
1416+
},
13971417
{
13981418
"command": "codeQL.openReferencedFileContextEditor",
13991419
"when": "resourceExtname == .qlref"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ export type LocalQueryCommands = {
9696
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
9797
"codeQL.codeLensQuickEval": (uri: Uri, range: Range) => Promise<void>;
9898
"codeQL.quickQuery": () => Promise<void>;
99+
"codeQL.getCurrentQuery": () => Promise<string>;
100+
};
101+
102+
// Debugger commands
103+
export type DebuggerCommands = {
104+
"codeQL.debug.quickEval": (uri: Uri) => Promise<void>;
105+
"codeQL.debug.quickEvalContextEditor": (uri: Uri) => Promise<void>;
99106
};
100107

101108
export type ResultsViewCommands = {
@@ -269,6 +276,7 @@ export type AllExtensionCommands = BaseCommands &
269276
ResultsViewCommands &
270277
QueryHistoryCommands &
271278
LocalDatabasesCommands &
279+
DebuggerCommands &
272280
VariantAnalysisCommands &
273281
DatabasePanelCommands &
274282
AstCfgCommands &

extensions/ql-vscode/src/debugger/debug-configuration.ts

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,38 @@ import {
66
} from "vscode";
77
import { getOnDiskWorkspaceFolders, showAndLogErrorMessage } from "../helpers";
88
import { LocalQueries } from "../local-queries";
9+
import { getQuickEvalContext, validateQueryPath } from "../run-queries-shared";
10+
import * as CodeQLDebugProtocol from "./debug-protocol";
911

12+
/**
13+
* The CodeQL launch arguments, as specified in "launch.json".
14+
*/
1015
interface QLDebugArgs {
11-
query: string;
12-
database: string;
13-
additionalPacks: string[] | string;
14-
extensionPacks: string[] | string;
16+
query?: string;
17+
database?: string;
18+
additionalPacks?: string[] | string;
19+
extensionPacks?: string[] | string;
20+
quickEval?: boolean;
21+
noDebug?: boolean;
1522
}
1623

17-
type QLDebugConfiguration = DebugConfiguration & Partial<QLDebugArgs>;
18-
19-
interface QLResolvedDebugArgs extends QLDebugArgs {
20-
additionalPacks: string[];
21-
extensionPacks: string[];
22-
}
24+
/**
25+
* The debug configuration for a CodeQL configuration.
26+
*
27+
* This just combines `QLDebugArgs` with the standard debug configuration properties.
28+
*/
29+
type QLDebugConfiguration = DebugConfiguration & QLDebugArgs;
2330

31+
/**
32+
* A CodeQL debug configuration after all variables and defaults have been resolved. This is what
33+
* is passed to the debug adapter via the `launch` request.
34+
*/
2435
export type QLResolvedDebugConfiguration = DebugConfiguration &
25-
QLResolvedDebugArgs;
36+
CodeQLDebugProtocol.LaunchConfig;
2637

38+
/**
39+
* Implementation of `DebugConfigurationProvider` for CodeQL.
40+
*/
2741
export class QLDebugConfigurationProvider
2842
implements DebugConfigurationProvider
2943
{
@@ -36,10 +50,12 @@ export class QLDebugConfigurationProvider
3650
): DebugConfiguration {
3751
const qlConfiguration = <QLDebugConfiguration>debugConfiguration;
3852

39-
// Fill in defaults
53+
// Fill in defaults for properties whose default value is a command invocation. VS Code will
54+
// invoke any commands to fill in actual values, then call
55+
// `resolveDebugConfigurationWithSubstitutedVariables()`with the result.
4056
const resultConfiguration: QLDebugConfiguration = {
4157
...qlConfiguration,
42-
query: qlConfiguration.query ?? "${file}",
58+
query: qlConfiguration.query ?? "${command:currentQuery}",
4359
database: qlConfiguration.database ?? "${command:currentDatabase}",
4460
};
4561

@@ -83,12 +99,23 @@ export class QLDebugConfigurationProvider
8399
? [qlConfiguration.extensionPacks]
84100
: qlConfiguration.extensionPacks;
85101

102+
const quickEval = qlConfiguration.quickEval ?? false;
103+
validateQueryPath(qlConfiguration.query, quickEval);
104+
105+
const quickEvalContext = quickEval
106+
? await getQuickEvalContext(undefined)
107+
: undefined;
108+
86109
const resultConfiguration: QLResolvedDebugConfiguration = {
87-
...qlConfiguration,
110+
name: qlConfiguration.name,
111+
request: qlConfiguration.request,
112+
type: qlConfiguration.type,
88113
query: qlConfiguration.query,
89114
database: qlConfiguration.database,
90115
additionalPacks,
91116
extensionPacks,
117+
quickEvalPosition: quickEvalContext?.quickEvalPosition,
118+
noDebug: qlConfiguration.noDebug ?? false,
92119
};
93120

94121
return resultConfiguration;

extensions/ql-vscode/src/debugger/debug-protocol.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export interface EvaluationStartedEventBody {
1717
outputDir: string;
1818
}
1919

20+
/**
21+
* Custom event to provide additional information about a running evaluation.
22+
*/
2023
export interface EvaluationStartedEvent extends DebugProtocol.Event {
2124
event: "codeql-evaluation-started";
2225
body: EvaluationStartedEventBody;
@@ -28,6 +31,9 @@ export interface EvaluationCompletedEventBody {
2831
evaluationTime: number;
2932
}
3033

34+
/**
35+
* Custom event to provide additional information about a completed evaluation.
36+
*/
3137
export interface EvaluationCompletedEvent extends DebugProtocol.Event {
3238
event: "codeql-evaluation-completed";
3339
body: EvaluationCompletedEventBody;
@@ -61,10 +67,28 @@ export type AnyResponse = InitializeResponse;
6167

6268
export type AnyProtocolMessage = AnyEvent | AnyRequest | AnyResponse;
6369

64-
export interface LaunchRequestArguments
65-
extends DebugProtocol.LaunchRequestArguments {
70+
export interface Position {
71+
fileName: string;
72+
line: number;
73+
column: number;
74+
endLine: number;
75+
endColumn: number;
76+
}
77+
78+
export interface LaunchConfig {
79+
/** Full path to query (.ql) file. */
6680
query: string;
81+
/** Full path to the database directory. */
6782
database: string;
83+
/** Full paths to `--additional-packs` directories. */
6884
additionalPacks: string[];
85+
/** Pack names of extension packs. */
6986
extensionPacks: string[];
87+
/** Optional quick evaluation position. */
88+
quickEvalPosition: Position | undefined;
89+
/** Run the query without debugging it. */
90+
noDebug: boolean;
7091
}
92+
93+
export type LaunchRequestArguments = DebugProtocol.LaunchRequestArguments &
94+
LaunchConfig;

0 commit comments

Comments
 (0)