Skip to content

Commit bd9da79

Browse files
committed
add progress bar when submit
1 parent 812544a commit bd9da79

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/commands/submit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as vscode from "vscode";
44
import { leetCodeManager } from "../leetCodeManager";
55
import { leetCodeBinaryPath } from "../shared";
6-
import { executeCommand } from "../utils/cpUtils";
6+
import { executeCommandWithProgress } from "../utils/cpUtils";
77
import { DialogType, promptForOpenOutputChannel, promptForSignIn, showResultFile } from "../utils/uiUtils";
88
import { getActivefilePath } from "../utils/workspaceUtils";
99

@@ -19,7 +19,7 @@ export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode
1919
}
2020

2121
try {
22-
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", `"${filePath}"`]);
22+
const result: string = await executeCommandWithProgress("Submitting to LeetCode...", channel, "node", [leetCodeBinaryPath, "submit", `"${filePath}"`]);
2323
await showResultFile(result);
2424
} catch (error) {
2525
await promptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.", DialogType.error, channel);

src/commands/test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as fse from "fs-extra";
44
import * as vscode from "vscode";
55
import { leetCodeManager } from "../leetCodeManager";
66
import { IQuickItemEx, leetCodeBinaryPath, UserStatus } from "../shared";
7-
import { executeCommand } from "../utils/cpUtils";
7+
import { executeCommandWithProgress } from "../utils/cpUtils";
88
import { DialogType, promptForOpenOutputChannel, showFileSelectDialog, showResultFile } from "../utils/uiUtils";
99
import { getActivefilePath } from "../utils/workspaceUtils";
1010

@@ -47,7 +47,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
4747
let result: string | undefined;
4848
switch (choice.value) {
4949
case ":default":
50-
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`]);
50+
result = await executeCommandWithProgress("Submitting to LeetCode...", channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`]);
5151
break;
5252
case ":direct":
5353
const testString: string | undefined = await vscode.window.showInputBox({
@@ -57,15 +57,15 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
5757
ignoreFocusOut: true,
5858
});
5959
if (testString) {
60-
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${testString.replace(/"/g, "")}"`]);
60+
result = await executeCommandWithProgress("Submitting to LeetCode...", channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${testString.replace(/"/g, "")}"`]);
6161
}
6262
break;
6363
case ":file":
6464
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog();
6565
if (testFile && testFile.length) {
6666
const input: string = await fse.readFile(testFile[0].fsPath, "utf-8");
6767
if (input.trim()) {
68-
result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${input.replace(/"/g, "").replace(/\r?\n/g, "\\n")}"`]);
68+
result = await executeCommandWithProgress("Submitting to LeetCode...", channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${input.replace(/"/g, "").replace(/\r?\n/g, "\\n")}"`]);
6969
} else {
7070
vscode.window.showErrorMessage("The selected test file must not be empty.");
7171
}

src/utils/cpUtils.ts

+16
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ export async function executeCommand(channel: vscode.OutputChannel, command: str
2626
});
2727
});
2828
}
29+
30+
export async function executeCommandWithProgress(message: string, channel: vscode.OutputChannel, command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
31+
let result: string = "";
32+
await vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async (p: vscode.Progress<{}>) => {
33+
return new Promise(async (resolve: () => void, reject: (e: Error) => void): Promise<void> => {
34+
p.report({ message });
35+
try {
36+
result = await executeCommand(channel, command, args, options);
37+
resolve();
38+
} catch (e) {
39+
reject(e);
40+
}
41+
});
42+
});
43+
return result;
44+
}

0 commit comments

Comments
 (0)