Skip to content

Commit 19400a9

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Add function for executing autofix
1 parent 03585af commit 19400a9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

extensions/ql-vscode/src/variant-analysis/view-autofixes.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { readRepoTask } from "./repo-tasks-store";
2323
import { unlink, mkdtemp } from "fs/promises";
2424
import { tmpdir } from "os";
2525
import { spawn } from "child_process";
26+
import type { execFileSync } from "child_process";
2627

2728
// Limit to three repos when generating autofixes so not sending
2829
// too many requests to autofix. Since we only need to validate
@@ -568,3 +569,33 @@ function createVarAutofixArgs(
568569

569570
return args;
570571
}
572+
573+
/**
574+
* Executes the autofix command.
575+
*/
576+
function execAutofix(
577+
logger: NotificationLogger,
578+
bin: string,
579+
args: string[],
580+
options: Parameters<typeof execFileSync>[2],
581+
showCommand?: boolean,
582+
): Promise<void> {
583+
return new Promise((resolve, reject) => {
584+
try {
585+
const cwd = options?.cwd || process.cwd();
586+
if (showCommand) {
587+
void logger.log(`Spawning '${bin} ${args.join(" ")}' in ${cwd}`);
588+
}
589+
if (args.some((a) => a === undefined || a === "")) {
590+
throw new Error(
591+
`Invalid empty or undefined arguments: ${args.join(" ")}`,
592+
);
593+
}
594+
const p = spawn(bin, args, { stdio: [0, 1, 2], ...options });
595+
p.on("error", reject);
596+
p.on("exit", (code) => (code === 0 ? resolve() : reject(code)));
597+
} catch (e) {
598+
reject(e);
599+
}
600+
});
601+
}

0 commit comments

Comments
 (0)