Skip to content

Commit aef836f

Browse files
author
Dave Bartolomeo
committed
Move LocalQueries commands to be member functions
1 parent 41e0702 commit aef836f

1 file changed

Lines changed: 138 additions & 135 deletions

File tree

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

Lines changed: 138 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -225,151 +225,154 @@ export class LocalQueries extends DisposableObject {
225225
}
226226

227227
public getCommands(): LocalQueryCommands {
228-
const runQuery = async (uri: Uri | undefined) =>
229-
withProgress(
230-
async (progress, token) => {
231-
await this.compileAndRunQuery(false, uri, progress, token, undefined);
232-
},
233-
{
234-
title: "Running query",
235-
cancellable: true,
236-
},
237-
);
228+
return {
229+
"codeQL.runQuery": this.runQuery.bind(this),
230+
"codeQL.runQueryContextEditor": this.runQuery.bind(this),
231+
"codeQL.runQueryOnMultipleDatabases":
232+
this.runQueryOnMultipleDatabases.bind(this),
233+
"codeQL.runQueryOnMultipleDatabasesContextEditor":
234+
this.runQueryOnMultipleDatabases.bind(this),
235+
"codeQL.runQueries": this.runQueries.bind(this),
236+
"codeQL.quickEval": this.quickEval.bind(this),
237+
"codeQL.quickEvalContextEditor": this.quickEval.bind(this),
238+
"codeQL.codeLensQuickEval": this.codeLensQuickEval.bind(this),
239+
"codeQL.quickQuery": this.quickQuery.bind(this),
240+
};
241+
}
238242

239-
const runQueryOnMultipleDatabases = async (uri: Uri | undefined) =>
240-
withProgress(
241-
async (progress, token) =>
242-
await this.compileAndRunQueryOnMultipleDatabases(
243-
progress,
244-
token,
245-
uri,
246-
),
247-
{
248-
title: "Running query on selected databases",
249-
cancellable: true,
250-
},
251-
);
243+
private async runQuery(uri: Uri | undefined): Promise<void> {
244+
await withProgress(
245+
async (progress, token) => {
246+
await this.compileAndRunQuery(false, uri, progress, token, undefined);
247+
},
248+
{
249+
title: "Running query",
250+
cancellable: true,
251+
},
252+
);
253+
}
254+
255+
private async runQueryOnMultipleDatabases(
256+
uri: Uri | undefined,
257+
): Promise<void> {
258+
await withProgress(
259+
async (progress, token) =>
260+
await this.compileAndRunQueryOnMultipleDatabases(progress, token, uri),
261+
{
262+
title: "Running query on selected databases",
263+
cancellable: true,
264+
},
265+
);
266+
}
252267

253-
const runQueries = async (_: Uri | undefined, multi: Uri[]) =>
254-
withProgress(
255-
async (progress, token) => {
256-
const maxQueryCount = MAX_QUERIES.getValue() as number;
257-
const [files, dirFound] = await gatherQlFiles(
258-
multi.map((uri) => uri.fsPath),
268+
private async runQueries(_: Uri | undefined, multi: Uri[]): Promise<void> {
269+
await withProgress(
270+
async (progress, token) => {
271+
const maxQueryCount = MAX_QUERIES.getValue() as number;
272+
const [files, dirFound] = await gatherQlFiles(
273+
multi.map((uri) => uri.fsPath),
274+
);
275+
if (files.length > maxQueryCount) {
276+
throw new Error(
277+
`You tried to run ${files.length} queries, but the maximum is ${maxQueryCount}. Try selecting fewer queries or changing the 'codeQL.runningQueries.maxQueries' setting.`,
259278
);
260-
if (files.length > maxQueryCount) {
261-
throw new Error(
262-
`You tried to run ${files.length} queries, but the maximum is ${maxQueryCount}. Try selecting fewer queries or changing the 'codeQL.runningQueries.maxQueries' setting.`,
263-
);
264-
}
265-
// warn user and display selected files when a directory is selected because some ql
266-
// files may be hidden from the user.
267-
if (dirFound) {
268-
const fileString = files.map((file) => basename(file)).join(", ");
269-
const res = await showBinaryChoiceDialog(
270-
`You are about to run ${files.length} queries: ${fileString} Do you want to continue?`,
271-
);
272-
if (!res) {
273-
return;
274-
}
275-
}
276-
const queryUris = files.map((path) =>
277-
Uri.parse(`file:${path}`, true),
279+
}
280+
// warn user and display selected files when a directory is selected because some ql
281+
// files may be hidden from the user.
282+
if (dirFound) {
283+
const fileString = files.map((file) => basename(file)).join(", ");
284+
const res = await showBinaryChoiceDialog(
285+
`You are about to run ${files.length} queries: ${fileString} Do you want to continue?`,
278286
);
279-
280-
// Use a wrapped progress so that messages appear with the queries remaining in it.
281-
let queriesRemaining = queryUris.length;
282-
283-
function wrappedProgress(update: ProgressUpdate) {
284-
const message =
285-
queriesRemaining > 1
286-
? `${queriesRemaining} remaining. ${update.message}`
287-
: update.message;
288-
progress({
289-
...update,
290-
message,
291-
});
287+
if (!res) {
288+
return;
292289
}
293-
294-
wrappedProgress({
295-
maxStep: queryUris.length,
296-
step: queryUris.length - queriesRemaining,
297-
message: "",
290+
}
291+
const queryUris = files.map((path) => Uri.parse(`file:${path}`, true));
292+
293+
// Use a wrapped progress so that messages appear with the queries remaining in it.
294+
let queriesRemaining = queryUris.length;
295+
296+
function wrappedProgress(update: ProgressUpdate) {
297+
const message =
298+
queriesRemaining > 1
299+
? `${queriesRemaining} remaining. ${update.message}`
300+
: update.message;
301+
progress({
302+
...update,
303+
message,
298304
});
305+
}
299306

300-
await Promise.all(
301-
queryUris.map(async (uri) =>
302-
this.compileAndRunQuery(
303-
false,
304-
uri,
305-
wrappedProgress,
306-
token,
307-
undefined,
308-
).then(() => queriesRemaining--),
309-
),
310-
);
311-
},
312-
{
313-
title: "Running queries",
314-
cancellable: true,
315-
},
316-
);
317-
318-
const quickEval = async (uri: Uri) =>
319-
withProgress(
320-
async (progress, token) => {
321-
await this.compileAndRunQuery(true, uri, progress, token, undefined);
322-
},
323-
{
324-
title: "Running query",
325-
cancellable: true,
326-
},
327-
);
328-
329-
const codeLensQuickEval = async (uri: Uri, range: Range) =>
330-
withProgress(
331-
async (progress, token) =>
332-
await this.compileAndRunQuery(
333-
true,
334-
uri,
335-
progress,
336-
token,
337-
undefined,
338-
range,
307+
wrappedProgress({
308+
maxStep: queryUris.length,
309+
step: queryUris.length - queriesRemaining,
310+
message: "",
311+
});
312+
313+
await Promise.all(
314+
queryUris.map(async (uri) =>
315+
this.compileAndRunQuery(
316+
false,
317+
uri,
318+
wrappedProgress,
319+
token,
320+
undefined,
321+
).then(() => queriesRemaining--),
339322
),
340-
{
341-
title: "Running query",
342-
cancellable: true,
343-
},
344-
);
323+
);
324+
},
325+
{
326+
title: "Running queries",
327+
cancellable: true,
328+
},
329+
);
330+
}
345331

346-
const quickQuery = async () =>
347-
withProgress(
348-
async (progress, token) =>
349-
displayQuickQuery(
350-
this.app,
351-
this.cliServer,
352-
this.databaseUI,
353-
progress,
354-
token,
355-
),
356-
{
357-
title: "Run Quick Query",
358-
},
359-
);
332+
private async quickEval(uri: Uri): Promise<void> {
333+
await withProgress(
334+
async (progress, token) => {
335+
await this.compileAndRunQuery(true, uri, progress, token, undefined);
336+
},
337+
{
338+
title: "Running query",
339+
cancellable: true,
340+
},
341+
);
342+
}
360343

361-
return {
362-
"codeQL.runQuery": runQuery,
363-
"codeQL.runQueryContextEditor": runQuery,
364-
"codeQL.runQueryOnMultipleDatabases": runQueryOnMultipleDatabases,
365-
"codeQL.runQueryOnMultipleDatabasesContextEditor":
366-
runQueryOnMultipleDatabases,
367-
"codeQL.runQueries": runQueries,
368-
"codeQL.quickEval": quickEval,
369-
"codeQL.quickEvalContextEditor": quickEval,
370-
"codeQL.codeLensQuickEval": codeLensQuickEval,
371-
"codeQL.quickQuery": quickQuery,
372-
};
344+
private async codeLensQuickEval(uri: Uri, range: Range): Promise<void> {
345+
await withProgress(
346+
async (progress, token) =>
347+
await this.compileAndRunQuery(
348+
true,
349+
uri,
350+
progress,
351+
token,
352+
undefined,
353+
range,
354+
),
355+
{
356+
title: "Running query",
357+
cancellable: true,
358+
},
359+
);
360+
}
361+
362+
private async quickQuery(): Promise<void> {
363+
await withProgress(
364+
async (progress, token) =>
365+
displayQuickQuery(
366+
this.app,
367+
this.cliServer,
368+
this.databaseUI,
369+
progress,
370+
token,
371+
),
372+
{
373+
title: "Run Quick Query",
374+
},
375+
);
373376
}
374377

375378
/**

0 commit comments

Comments
 (0)