Merge pull request #2245 from github/dbartol/local-queries-commands

Move `LocalQueries` commands to be member functions
This commit is contained in:
Dave Bartolomeo
2023-03-31 14:31:44 -04:00
committed by GitHub

View File

@@ -225,8 +225,23 @@ export class LocalQueries extends DisposableObject {
} }
public getCommands(): LocalQueryCommands { public getCommands(): LocalQueryCommands {
const runQuery = async (uri: Uri | undefined) => return {
withProgress( "codeQL.runQuery": this.runQuery.bind(this),
"codeQL.runQueryContextEditor": this.runQuery.bind(this),
"codeQL.runQueryOnMultipleDatabases":
this.runQueryOnMultipleDatabases.bind(this),
"codeQL.runQueryOnMultipleDatabasesContextEditor":
this.runQueryOnMultipleDatabases.bind(this),
"codeQL.runQueries": this.runQueries.bind(this),
"codeQL.quickEval": this.quickEval.bind(this),
"codeQL.quickEvalContextEditor": this.quickEval.bind(this),
"codeQL.codeLensQuickEval": this.codeLensQuickEval.bind(this),
"codeQL.quickQuery": this.quickQuery.bind(this),
};
}
private async runQuery(uri: Uri | undefined): Promise<void> {
await withProgress(
async (progress, token) => { async (progress, token) => {
await this.compileAndRunQuery(false, uri, progress, token, undefined); await this.compileAndRunQuery(false, uri, progress, token, undefined);
}, },
@@ -235,23 +250,23 @@ export class LocalQueries extends DisposableObject {
cancellable: true, cancellable: true,
}, },
); );
}
const runQueryOnMultipleDatabases = async (uri: Uri | undefined) => private async runQueryOnMultipleDatabases(
withProgress( uri: Uri | undefined,
): Promise<void> {
await withProgress(
async (progress, token) => async (progress, token) =>
await this.compileAndRunQueryOnMultipleDatabases( await this.compileAndRunQueryOnMultipleDatabases(progress, token, uri),
progress,
token,
uri,
),
{ {
title: "Running query on selected databases", title: "Running query on selected databases",
cancellable: true, cancellable: true,
}, },
); );
}
const runQueries = async (_: Uri | undefined, multi: Uri[]) => private async runQueries(_: Uri | undefined, multi: Uri[]): Promise<void> {
withProgress( await withProgress(
async (progress, token) => { async (progress, token) => {
const maxQueryCount = MAX_QUERIES.getValue() as number; const maxQueryCount = MAX_QUERIES.getValue() as number;
const [files, dirFound] = await gatherQlFiles( const [files, dirFound] = await gatherQlFiles(
@@ -273,9 +288,7 @@ export class LocalQueries extends DisposableObject {
return; return;
} }
} }
const queryUris = files.map((path) => const queryUris = files.map((path) => Uri.parse(`file:${path}`, true));
Uri.parse(`file:${path}`, true),
);
// Use a wrapped progress so that messages appear with the queries remaining in it. // Use a wrapped progress so that messages appear with the queries remaining in it.
let queriesRemaining = queryUris.length; let queriesRemaining = queryUris.length;
@@ -314,9 +327,10 @@ export class LocalQueries extends DisposableObject {
cancellable: true, cancellable: true,
}, },
); );
}
const quickEval = async (uri: Uri) => private async quickEval(uri: Uri): Promise<void> {
withProgress( await withProgress(
async (progress, token) => { async (progress, token) => {
await this.compileAndRunQuery(true, uri, progress, token, undefined); await this.compileAndRunQuery(true, uri, progress, token, undefined);
}, },
@@ -325,9 +339,10 @@ export class LocalQueries extends DisposableObject {
cancellable: true, cancellable: true,
}, },
); );
}
const codeLensQuickEval = async (uri: Uri, range: Range) => private async codeLensQuickEval(uri: Uri, range: Range): Promise<void> {
withProgress( await withProgress(
async (progress, token) => async (progress, token) =>
await this.compileAndRunQuery( await this.compileAndRunQuery(
true, true,
@@ -342,9 +357,10 @@ export class LocalQueries extends DisposableObject {
cancellable: true, cancellable: true,
}, },
); );
}
const quickQuery = async () => private async quickQuery(): Promise<void> {
withProgress( await withProgress(
async (progress, token) => async (progress, token) =>
displayQuickQuery( displayQuickQuery(
this.app, this.app,
@@ -357,19 +373,6 @@ export class LocalQueries extends DisposableObject {
title: "Run Quick Query", title: "Run Quick Query",
}, },
); );
return {
"codeQL.runQuery": runQuery,
"codeQL.runQueryContextEditor": runQuery,
"codeQL.runQueryOnMultipleDatabases": runQueryOnMultipleDatabases,
"codeQL.runQueryOnMultipleDatabasesContextEditor":
runQueryOnMultipleDatabases,
"codeQL.runQueries": runQueries,
"codeQL.quickEval": quickEval,
"codeQL.quickEvalContextEditor": quickEval,
"codeQL.codeLensQuickEval": codeLensQuickEval,
"codeQL.quickQuery": quickQuery,
};
} }
/** /**