Skip to content

Commit 6ae6e91

Browse files
committed
Add maximum number of queries to run
Throw error if user tries to run more than that.
1 parent fabef96 commit 6ae6e91

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,20 +444,28 @@ async function activateWithInstalledDistribution(
444444
commands.registerCommand(
445445
'codeQL.runQueries',
446446
async (_: Uri | undefined, multi: Uri[]) => {
447-
const [files, dirFound] = await gatherQlFiles(multi.map(uri => uri.fsPath));
448-
// warn user and display selected files when a directory is selected because some ql
449-
// files may be hidden from the user.
450-
if (dirFound) {
451-
const fileString = files.map(file => path.basename(file)).join(', ');
452-
const res = await helpers.showBinaryChoiceDialog(
453-
`You are about to run ${files.length} queries: ${fileString} Do you want to continue?`
454-
);
455-
if (!res) {
456-
return;
447+
const maxQueryCount = 20;
448+
try {
449+
const [files, dirFound] = await gatherQlFiles(multi.map(uri => uri.fsPath));
450+
if (files.length > maxQueryCount) {
451+
throw new Error(`You tried to run ${files.length} queries, but the maximum is ${maxQueryCount}. Try selecting fewer queries.`);
457452
}
453+
// warn user and display selected files when a directory is selected because some ql
454+
// files may be hidden from the user.
455+
if (dirFound) {
456+
const fileString = files.map(file => path.basename(file)).join(', ');
457+
const res = await helpers.showBinaryChoiceDialog(
458+
`You are about to run ${files.length} queries: ${fileString} Do you want to continue?`
459+
);
460+
if (!res) {
461+
return;
462+
}
463+
}
464+
const queryUris = files.map(path => Uri.parse(`file:${path}`, true));
465+
await Promise.all(queryUris.map(uri => compileAndRunQuery(false, uri)));
466+
} catch (e) {
467+
helpers.showAndLogErrorMessage(e.message);
458468
}
459-
const queryUris = files.map(path => Uri.parse(`file:${path}`, true));
460-
await Promise.all(queryUris.map(uri => compileAndRunQuery(false, uri)));
461469
}
462470
)
463471
);

0 commit comments

Comments
 (0)