Skip to content

Commit 22172d5

Browse files
author
Alexander Eyers-Taylor
authored
Add support for quick eval count to the query runner (#2417)
* Add support for quick eval count to the query runner This only adds support internally to the query runner, without any UI support. * Fix some tests
1 parent af3be54 commit 22172d5

File tree

14 files changed

+77
-25
lines changed

14 files changed

+77
-25
lines changed

extensions/ql-vscode/src/data-extensions-editor/external-api-usage-query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export async function runQuery({
7878

7979
const queryRun = queryRunner.createQueryRun(
8080
databaseItem.databaseUri.fsPath,
81-
{ queryPath: queryFile, quickEvalPosition: undefined },
81+
{
82+
queryPath: queryFile,
83+
quickEvalPosition: undefined,
84+
quickEvalCountOnly: false,
85+
},
8286
false,
8387
getOnDiskWorkspaceFolders(),
8488
extensionPacks,

extensions/ql-vscode/src/data-extensions-editor/generate-flow-model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ async function getModeledMethodsFromFlow(
5353

5454
const queryRun = queryRunner.createQueryRun(
5555
databaseItem.databaseUri.fsPath,
56-
{ queryPath: query, quickEvalPosition: undefined },
56+
{
57+
queryPath: query,
58+
quickEvalPosition: undefined,
59+
quickEvalCountOnly: false,
60+
},
5761
false,
5862
getOnDiskWorkspaceFolders(),
5963
undefined,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class QLDebugConfigurationProvider
105105
validateQueryPath(qlConfiguration.query, quickEval);
106106

107107
const quickEvalContext = quickEval
108-
? await getQuickEvalContext(undefined)
108+
? await getQuickEvalContext(undefined, false)
109109
: undefined;
110110

111111
const resultConfiguration: QLResolvedDebugConfiguration = {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class RunningQuery extends DisposableObject {
155155
{
156156
queryPath: config.query,
157157
quickEvalPosition: quickEvalContext?.quickEvalPosition,
158+
quickEvalCountOnly: quickEvalContext?.quickEvalCount,
158159
},
159160
true,
160161
config.additionalPacks,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class QLDebugAdapterTracker
7474

7575
public async quickEval(): Promise<void> {
7676
const args: CodeQLProtocol.QuickEvalRequest["arguments"] = {
77-
quickEvalContext: await getQuickEvalContext(undefined),
77+
quickEvalContext: await getQuickEvalContext(undefined, false),
7878
};
7979
await this.session.customRequest("codeql-quickeval", args);
8080
}

extensions/ql-vscode/src/language-support/ast-viewer/ast-cfg-commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Uri, window } from "vscode";
22
import { withProgress } from "../../common/vscode/progress";
33
import { AstViewer } from "./ast-viewer";
44
import { AstCfgCommands } from "../../common/commands";
5-
import { LocalQueries } from "../../local-queries";
5+
import { LocalQueries, QuickEvalType } from "../../local-queries";
66
import {
77
TemplatePrintAstProvider,
88
TemplatePrintCfgProvider,
@@ -47,7 +47,7 @@ export function getAstCfgCommands({
4747
);
4848
if (res) {
4949
await localQueries.compileAndRunQuery(
50-
false,
50+
QuickEvalType.None,
5151
res[0],
5252
progress,
5353
token,

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ async function promptToSaveQueryIfNeeded(query: SelectedQuery): Promise<void> {
7272
}
7373
}
7474

75+
export enum QuickEvalType {
76+
None,
77+
QuickEval,
78+
QuickEvalCount,
79+
}
80+
7581
export class LocalQueries extends DisposableObject {
7682
public constructor(
7783
private readonly app: App,
@@ -115,7 +121,13 @@ export class LocalQueries extends DisposableObject {
115121
private async runQuery(uri: Uri | undefined): Promise<void> {
116122
await withProgress(
117123
async (progress, token) => {
118-
await this.compileAndRunQuery(false, uri, progress, token, undefined);
124+
await this.compileAndRunQuery(
125+
QuickEvalType.None,
126+
uri,
127+
progress,
128+
token,
129+
undefined,
130+
);
119131
},
120132
{
121133
title: "Running query",
@@ -185,7 +197,7 @@ export class LocalQueries extends DisposableObject {
185197
await Promise.all(
186198
queryUris.map(async (uri) =>
187199
this.compileAndRunQuery(
188-
false,
200+
QuickEvalType.None,
189201
uri,
190202
wrappedProgress,
191203
token,
@@ -204,7 +216,13 @@ export class LocalQueries extends DisposableObject {
204216
private async quickEval(uri: Uri): Promise<void> {
205217
await withProgress(
206218
async (progress, token) => {
207-
await this.compileAndRunQuery(true, uri, progress, token, undefined);
219+
await this.compileAndRunQuery(
220+
QuickEvalType.QuickEval,
221+
uri,
222+
progress,
223+
token,
224+
undefined,
225+
);
208226
},
209227
{
210228
title: "Running query",
@@ -217,7 +235,7 @@ export class LocalQueries extends DisposableObject {
217235
await withProgress(
218236
async (progress, token) =>
219237
await this.compileAndRunQuery(
220-
true,
238+
QuickEvalType.QuickEval,
221239
uri,
222240
progress,
223241
token,
@@ -331,7 +349,7 @@ export class LocalQueries extends DisposableObject {
331349
}
332350

333351
public async compileAndRunQuery(
334-
quickEval: boolean,
352+
quickEval: QuickEvalType,
335353
queryUri: Uri | undefined,
336354
progress: ProgressCallback,
337355
token: CancellationToken,
@@ -352,7 +370,7 @@ export class LocalQueries extends DisposableObject {
352370

353371
/** Used by tests */
354372
public async compileAndRunQueryInternal(
355-
quickEval: boolean,
373+
quickEval: QuickEvalType,
356374
queryUri: Uri | undefined,
357375
progress: ProgressCallback,
358376
token: CancellationToken,
@@ -364,15 +382,20 @@ export class LocalQueries extends DisposableObject {
364382
if (queryUri !== undefined) {
365383
// The query URI is provided by the command, most likely because the command was run from an
366384
// editor context menu. Use the provided URI, but make sure it's a valid query.
367-
queryPath = validateQueryUri(queryUri, quickEval);
385+
queryPath = validateQueryUri(queryUri, quickEval !== QuickEvalType.None);
368386
} else {
369387
// Use the currently selected query.
370-
queryPath = await this.getCurrentQuery(quickEval);
388+
queryPath = await this.getCurrentQuery(quickEval !== QuickEvalType.None);
371389
}
372390

373391
const selectedQuery: SelectedQuery = {
374392
queryPath,
375-
quickEval: quickEval ? await getQuickEvalContext(range) : undefined,
393+
quickEval: quickEval
394+
? await getQuickEvalContext(
395+
range,
396+
quickEval === QuickEvalType.QuickEvalCount,
397+
)
398+
: undefined,
376399
};
377400

378401
// If no databaseItem is specified, use the database currently selected in the Databases UI
@@ -392,6 +415,7 @@ export class LocalQueries extends DisposableObject {
392415
{
393416
queryPath: selectedQuery.queryPath,
394417
quickEvalPosition: selectedQuery.quickEval?.quickEvalPosition,
418+
quickEvalCountOnly: selectedQuery.quickEval?.quickEvalCount,
395419
},
396420
true,
397421
additionalPacks,
@@ -481,7 +505,7 @@ export class LocalQueries extends DisposableObject {
481505
for (const item of quickpick) {
482506
try {
483507
await this.compileAndRunQuery(
484-
false,
508+
QuickEvalType.None,
485509
uri,
486510
progress,
487511
token,

extensions/ql-vscode/src/pure/messages-shared.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export interface CompilationTarget {
6868
*/
6969
export interface QuickEvalOptions {
7070
quickEvalPos?: Position;
71+
/**
72+
* Whether to only count the number of results.
73+
*
74+
* This is only supported by the new query server
75+
* but it isn't worth having a separate type and
76+
* it is fine to have an ignored optional field.
77+
*/
78+
countOnly?: boolean;
7179
}
7280

7381
/**

extensions/ql-vscode/src/query-server/query-runner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export interface CoreQueryTarget {
1616
* `query`.
1717
*/
1818
quickEvalPosition?: Position;
19+
/**
20+
* If this is quick eval, whether to only count the number of results.
21+
*/
22+
quickEvalCountOnly?: boolean;
1923
}
2024

2125
export interface CoreQueryResults {

extensions/ql-vscode/src/query-server/run-queries.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export async function compileAndRunQueryAgainstDatabaseCore(
3636
const target =
3737
query.quickEvalPosition !== undefined
3838
? {
39-
quickEval: { quickEvalPos: query.quickEvalPosition },
39+
quickEval: {
40+
quickEvalPos: query.quickEvalPosition,
41+
countOnly: query.quickEvalCountOnly,
42+
},
4043
}
4144
: { query: {} };
4245

0 commit comments

Comments
 (0)