Skip to content

Commit

Permalink
Add quick eval count to the command palette (#2475)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexet authored Jun 27, 2023
1 parent 2a332f9 commit b0699ee
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 2 deletions.
3 changes: 3 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [UNRELEASED]

- Add `CodeQL: Quick Evaluation Count` command to generate the count summary statistics of the results set
without speding the time to compute locations and strings.

## 1.8.6 - 14 June 2023

- 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)
Expand Down
8 changes: 8 additions & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@
"command": "codeQL.quickEval",
"title": "CodeQL: Quick Evaluation"
},
{
"command": "codeQL.quickEvalCount",
"title": "CodeQL: Quick Evaluation Count"
},
{
"command": "codeQL.quickEvalContextEditor",
"title": "CodeQL: Quick Evaluation"
Expand Down Expand Up @@ -1245,6 +1249,10 @@
"command": "codeQL.quickEval",
"when": "editorLangId == ql"
},
{
"command": "codeQL.quickEvalCount",
"when": "editorLangId == ql && codeql.supportsQuickEvalCount"
},
{
"command": "codeQL.quickEvalContextEditor",
"when": "false"
Expand Down
18 changes: 18 additions & 0 deletions extensions/ql-vscode/src/codeql-cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,13 @@ export class CodeQLCliServer implements Disposable {
CliVersionConstraint.CLI_VERSION_WITH_PER_QUERY_EVAL_LOG,
) >= 0,
);
await this.app.commands.execute(
"setContext",
"codeql.supportsQuickEvalCount",
newVersion.compare(
CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT,
) >= 0,
);
} catch (e) {
this._versionChangedListeners.forEach((listener) =>
listener(undefined),
Expand Down Expand Up @@ -1845,6 +1852,11 @@ export class CliVersionConstraint {

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

/**
* CLI version where the query server supports quick-eval count mode.
*/
public static CLI_VERSION_WITH_QUICK_EVAL_COUNT = new SemVer("2.13.3");

constructor(private readonly cli: CodeQLCliServer) {
/**/
}
Expand Down Expand Up @@ -1918,4 +1930,10 @@ export class CliVersionConstraint {
async usesGlobalCompilationCache() {
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_GLOBAL_CACHE);
}

async supportsQuickEvalCount() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT,
);
}
}
1 change: 1 addition & 0 deletions extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export type LocalQueryCommands = {
"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>;
Expand Down
26 changes: 25 additions & 1 deletion extensions/ql-vscode/src/local-queries/local-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { CompletedLocalQueryInfo, LocalQueryInfo } from "../query-results";
import { WebviewReveal } from "./webview";
import { asError, getErrorMessage } from "../common/helpers-pure";
import { CodeQLCliServer } from "../codeql-cli/cli";
import { CliVersionConstraint, CodeQLCliServer } from "../codeql-cli/cli";
import { LocalQueryCommands } from "../common/commands";
import { App } from "../common/app";
import { DisposableObject } from "../common/disposable-object";
Expand Down Expand Up @@ -110,6 +110,7 @@ export class LocalQueries extends DisposableObject {
this.runQueries.bind(this),
),
"codeQL.quickEval": this.quickEval.bind(this),
"codeQL.quickEvalCount": this.quickEvalCount.bind(this),
"codeQL.quickEvalContextEditor": this.quickEval.bind(this),
"codeQL.codeLensQuickEval": this.codeLensQuickEval.bind(this),
"codeQL.quickQuery": this.quickQuery.bind(this),
Expand Down Expand Up @@ -243,6 +244,29 @@ export class LocalQueries extends DisposableObject {
);
}

private async quickEvalCount(uri: Uri): Promise<void> {
await withProgress(
async (progress, token) => {
if (!(await this.cliServer.cliConstraints.supportsQuickEvalCount())) {
throw new Error(
`Quick evaluation count is only supported by CodeQL CLI v${CliVersionConstraint.CLI_VERSION_WITH_QUICK_EVAL_COUNT} or later.`,
);
}
await this.compileAndRunQuery(
QuickEvalType.QuickEvalCount,
uri,
progress,
token,
undefined,
);
},
{
title: "Running query",
cancellable: true,
},
);
}

private async codeLensQuickEval(uri: Uri, range: Range): Promise<void> {
await withProgress(
async (progress, token) =>
Expand Down
5 changes: 4 additions & 1 deletion extensions/ql-vscode/src/query-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface InitialQueryInfo {
readonly queryText: string; // text of the selected file, or the selected text when doing quick eval
readonly isQuickQuery: boolean;
readonly isQuickEval: boolean;
readonly isQuickEvalCount?: boolean; // Missing is false for backwards compatibility
readonly quickEvalPosition?: messages.Position;
readonly queryPath: string;
readonly databaseInfo: DatabaseInfo;
Expand Down Expand Up @@ -270,7 +271,9 @@ export class LocalQueryInfo {
* - Otherwise, return the query file name.
*/
getQueryName() {
if (this.initialInfo.quickEvalPosition) {
if (this.initialInfo.isQuickEvalCount) {
return `Quick evaluation counts of ${this.getQueryFileName()}`;
} else if (this.initialInfo.isQuickEval) {
return `Quick evaluation of ${this.getQueryFileName()}`;
} else if (this.completedQuery?.query.metadata?.name) {
return this.completedQuery?.query.metadata?.name;
Expand Down
3 changes: 3 additions & 0 deletions extensions/ql-vscode/src/run-queries-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,12 @@ export async function createInitialQueryInfo(
databaseInfo: DatabaseInfo,
): Promise<InitialQueryInfo> {
const isQuickEval = selectedQuery.quickEval !== undefined;
const isQuickEvalCount =
selectedQuery.quickEval?.quickEvalCount !== undefined;
return {
queryPath: selectedQuery.queryPath,
isQuickEval,
isQuickEvalCount,
isQuickQuery: isQuickQueryPath(selectedQuery.queryPath),
databaseInfo,
id: `${basename(selectedQuery.queryPath)}-${nanoid()}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("query-results", () => {
endLine: 2,
fileName: "/home/users/yz",
};
(fqi.initialInfo as any).isQuickEval = true;
expect(fqi.getQueryName()).toBe("Quick evaluation of yz:1-2");
(fqi.initialInfo as any).quickEvalPosition.endLine = 1;
expect(fqi.getQueryName()).toBe("Quick evaluation of yz:1");
Expand Down

0 comments on commit b0699ee

Please sign in to comment.