Skip to content

Commit 3028be4

Browse files
Vigilansjdneo
authored andcommitted
Fix #236, #237 (#235)
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

+2-2
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

+8-1
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

+10-1
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) {
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)