8000 Fix #236, #237 (#235) · youngshuohao/vscode-leetcode@3028be4 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3028be4

Browse files
Vigilansjdneo
authored andcommitted
1 parent bcafa92 commit 3028be4

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/commands/show.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
6565
if (defaultLanguage && languages.indexOf(defaultLanguage) < 0) {
6666
defaultLanguage = undefined;
6767
}
68-
const language: string | undefined = defaultLanguage || await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use" });
68+
const language: string | undefined = defaultLanguage || await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use", ignoreFocusOut: true });
6969
// fire-and-forget default language query
7070
(async (): Promise<void> => {
71-
if (!defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
71+
if (language && !defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
7272
const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
7373
`Would you like to set '${language}' as your default language?`,
7474
DialogOptions.yes,

src/leetCodeExecutor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ class LeetCodeExecutor {
111111
}
112112

113113
public async submitSolution(filePath: string): Promise<string> {
114-
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
114+
try {
115+
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
116+
} catch (error) {
117+
if (error.result) {
118+
return error.result;
119+
}
120+
throw error;
121+
}
115122
}
116123

117124
public async testSolution(filePath: string, testString?: string): Promise<string> {

src/utils/cpUtils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import * as cp from "child_process";
55
import * as vscode from "vscode";
66
import { leetCodeChannel } from "../leetCodeChannel";
77

8+
interface IExecError extends Error {
9+
result?: string;
10+
}
11+
812
export async function executeCommand(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
913
return new Promise((resolve: (res: string) => void, reject: (e: Error) => void): void => {
1014
let result: string = "";
@@ -20,9 +24,14 @@ export async function executeCommand(command: string, args: string[], options: c
2024
childProc.stderr.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));
2125

2226
childProc.on("error", reject);
27+
2328
childProc.on("close", (code: number) => {
2429
if (code !== 0 || result.indexOf("ERROR") > -1) {
25-
reject(new Error(`Command "${command} ${args.toString()}" failed with exit code "${code}".`));
30+
const error: IExecError = new Error(`Command "${command} ${args.toString()}" failed with exit code "${code}".`);
31+
if (result) {
5740 32+
error.result = result; // leetcode-cli may print useful content by exit with error code
33+
}
34+
reject(error);
2635
} else {
2736
resolve(result);
2837
}

0 commit comments

Comments
 (0)
0