diff --git a/src/commands/test.ts b/src/commands/test.ts index d070c9aa..152f0976 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -42,6 +42,12 @@ export async function testSolution(uri?: vscode.Uri): Promise { detail: "Test with the written cases in file", value: ":file", }, + { + label: "$(debug-restart) Re-run last...", + description: "", + detail: "Test with the cases which were last run", + value: ":rerun", + }, ); const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(picks); if (!choice) { @@ -75,6 +81,13 @@ export async function testSolution(uri?: vscode.Uri): Promise { } } break; + case ":rerun": + if (leetCodeExecutor.lastTestString) { + result = await leetCodeExecutor.testSolution(filePath, leetCodeExecutor.lastTestString); + } else { // run default cases + result = await leetCodeExecutor.testSolution(filePath); + } + break; default: break; } diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index 5157b6c1..d8430c43 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -17,11 +17,13 @@ import { toWslPath, useWsl } from "./utils/wslUtils"; class LeetCodeExecutor implements Disposable { private leetCodeRootPath: string; private nodeExecutable: string; + private lastTest: string | undefined; private configurationChangeListener: Disposable; constructor() { this.leetCodeRootPath = path.join(__dirname, "..", "..", "node_modules", "vsc-leetcode-cli"); this.nodeExecutable = this.getNodePath(); + this.lastTest = ""; this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => { if (event.affectsConfiguration("leetcode.nodePath")) { this.nodeExecutable = this.getNodePath(); @@ -142,6 +144,7 @@ class LeetCodeExecutor implements Disposable { } public async testSolution(filePath: string, testString?: string): Promise { + this.lastTest = testString; if (testString) { return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]); } @@ -181,6 +184,10 @@ class LeetCodeExecutor implements Disposable { return this.nodeExecutable; } + public get lastTestString(): string | undefined { + return this.lastTest; + } + public dispose(): void { this.configurationChangeListener.dispose(); }