Skip to content

Commit b0699ee

Browse files
author
Alexander Eyers-Taylor
authored
Add quick eval count to the command palette (#2475)
* Add version constraint for quick-eval-count * Add quick eval count context. * Add support for running quick-eval-count from the command pallete * Adjust name for quick-eval-count-queries * Add changenote for quick-eval-count. * QuickEval:Address review comments * Fix rebase conflict in changelog
1 parent 2a332f9 commit b0699ee

File tree

8 files changed

+63
-2
lines changed

8 files changed

+63
-2
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [UNRELEASED]
44

5+
- Add `CodeQL: Quick Evaluation Count` command to generate the count summary statistics of the results set
6+
without speding the time to compute locations and strings.
7+
58
## 1.8.6 - 14 June 2023
69

710
- Add repositories to a variant analysis list with GitHub Code Search. [#2439](https://github.com/github/vscode-codeql/pull/2439) and [#2476](https://github.com/github/vscode-codeql/pull/2476)

extensions/ql-vscode/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@
457457
"command": "codeQL.quickEval",
458458
"title": "CodeQL: Quick Evaluation"
459459
},
460+
{
461+
"command": "codeQL.quickEvalCount",
462+
"title": "CodeQL: Quick Evaluation Count"
463+
},
460464
{
461465
"command": "codeQL.quickEvalContextEditor",
462466
"title": "CodeQL: Quick Evaluation"
@@ -1245,6 +1249,10 @@
12451249
"command": "codeQL.quickEval",
12461250
"when": "editorLangId == ql"
12471251
},
1252+
{
1253+
"command": "codeQL.quickEvalCount",
1254+
"when": "editorLangId == ql && codeql.supportsQuickEvalCount"
1255+
},
12481256
{
12491257
"command": "codeQL.quickEvalContextEditor",
12501258
"when": "false"

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,13 @@ export class CodeQLCliServer implements Disposable {
14831483
CliVersionConstraint.CLI_VERSION_WITH_PER_QUERY_EVAL_LOG,
14841484
) >= 0,
14851485
);
1486+
await this.app.commands.execute(
1487+
"setContext",
1488+
"codeql.supportsQuickEvalCount",
1489+
newVersion.compare(
1490+
CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT,
1491+
) >= 0,
1492+
);
14861493
} catch (e) {
14871494
this._versionChangedListeners.forEach((listener) =>
14881495
listener(undefined),
@@ -1845,6 +1852,11 @@ export class CliVersionConstraint {
18451852

18461853
public static CLI_VERSION_GLOBAL_CACHE = new SemVer("2.12.4");
18471854

1855+
/**
1856+
* CLI version where the query server supports quick-eval count mode.
1857+
*/
1858+
public static CLI_VERSION_WITH_QUICK_EVAL_COUNT = new SemVer("2.13.3");
1859+
18481860
constructor(private readonly cli: CodeQLCliServer) {
18491861
/**/
18501862
}
@@ -1918,4 +1930,10 @@ export class CliVersionConstraint {
19181930
async usesGlobalCompilationCache() {
19191931
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_GLOBAL_CACHE);
19201932
}
1933+
1934+
async supportsQuickEvalCount() {
1935+
return this.isVersionAtLeast(
1936+
CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT,
1937+
);
1938+
}
19211939
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export type LocalQueryCommands = {
135135
"codeQL.runLocalQueryFromFileTab": (uri: Uri) => Promise<void>;
136136
"codeQL.runQueries": ExplorerSelectionCommandFunction<Uri>;
137137
"codeQL.quickEval": (uri: Uri) => Promise<void>;
138+
"codeQL.quickEvalCount": (uri: Uri) => Promise<void>;
138139
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;
139140
"codeQL.codeLensQuickEval": (uri: Uri, range: Range) => Promise<void>;
140141
"codeQL.quickQuery": () => Promise<void>;

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
import { CompletedLocalQueryInfo, LocalQueryInfo } from "../query-results";
4141
import { WebviewReveal } from "./webview";
4242
import { asError, getErrorMessage } from "../common/helpers-pure";
43-
import { CodeQLCliServer } from "../codeql-cli/cli";
43+
import { CliVersionConstraint, CodeQLCliServer } from "../codeql-cli/cli";
4444
import { LocalQueryCommands } from "../common/commands";
4545
import { App } from "../common/app";
4646
import { DisposableObject } from "../common/disposable-object";
@@ -110,6 +110,7 @@ export class LocalQueries extends DisposableObject {
110110
this.runQueries.bind(this),
111111
),
112112
"codeQL.quickEval": this.quickEval.bind(this),
113+
"codeQL.quickEvalCount": this.quickEvalCount.bind(this),
113114
"codeQL.quickEvalContextEditor": this.quickEval.bind(this),
114115
"codeQL.codeLensQuickEval": this.codeLensQuickEval.bind(this),
115116
"codeQL.quickQuery": this.quickQuery.bind(this),
@@ -243,6 +244,29 @@ export class LocalQueries extends DisposableObject {
243244
);
244245
}
245246

247+
private async quickEvalCount(uri: Uri): Promise<void> {
248+
await withProgress(
249+
async (progress, token) => {
250+
if (!(await this.cliServer.cliConstraints.supportsQuickEvalCount())) {
251+
throw new Error(
252+
`Quick evaluation count is only supported by CodeQL CLI v${CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT} or later.`,
253+
);
254+
}
255+
await this.compileAndRunQuery(
256+
QuickEvalType.QuickEvalCount,
257+
uri,
258+
progress,
259+
token,
260+
undefined,
261+
);
262+
},
263+
{
264+
title: "Running query",
265+
cancellable: true,
266+
},
267+
);
268+
}
269+
246270
private async codeLensQuickEval(uri: Uri, range: Range): Promise<void> {
247271
await withProgress(
248272
async (progress, token) =>

extensions/ql-vscode/src/query-results.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface InitialQueryInfo {
4141
readonly queryText: string; // text of the selected file, or the selected text when doing quick eval
4242
readonly isQuickQuery: boolean;
4343
readonly isQuickEval: boolean;
44+
readonly isQuickEvalCount?: boolean; // Missing is false for backwards compatibility
4445
readonly quickEvalPosition?: messages.Position;
4546
readonly queryPath: string;
4647
readonly databaseInfo: DatabaseInfo;
@@ -270,7 +271,9 @@ export class LocalQueryInfo {
270271
* - Otherwise, return the query file name.
271272
*/
272273
getQueryName() {
273-
if (this.initialInfo.quickEvalPosition) {
274+
if (this.initialInfo.isQuickEvalCount) {
275+
return `Quick evaluation counts of ${this.getQueryFileName()}`;
276+
} else if (this.initialInfo.isQuickEval) {
274277
return `Quick evaluation of ${this.getQueryFileName()}`;
275278
} else if (this.completedQuery?.query.metadata?.name) {
276279
return this.completedQuery?.query.metadata?.name;

extensions/ql-vscode/src/run-queries-shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,12 @@ export async function createInitialQueryInfo(
585585
databaseInfo: DatabaseInfo,
586586
): Promise<InitialQueryInfo> {
587587
const isQuickEval = selectedQuery.quickEval !== undefined;
588+
const isQuickEvalCount =
589+
selectedQuery.quickEval?.quickEvalCount !== undefined;
588590
return {
589591
queryPath: selectedQuery.queryPath,
590592
isQuickEval,
593+
isQuickEvalCount,
591594
isQuickQuery: isQuickQueryPath(selectedQuery.queryPath),
592595
databaseInfo,
593596
id: `${basename(selectedQuery.queryPath)}-${nanoid()}`,

extensions/ql-vscode/test/vscode-tests/no-workspace/query-results.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("query-results", () => {
5858
endLine: 2,
5959
fileName: "/home/users/yz",
6060
};
61+
(fqi.initialInfo as any).isQuickEval = true;
6162
expect(fqi.getQueryName()).toBe("Quick evaluation of yz:1-2");
6263
(fqi.initialInfo as any).quickEvalPosition.endLine = 1;
6364
expect(fqi.getQueryName()).toBe("Quick evaluation of yz:1");

0 commit comments

Comments
 (0)