Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Several behavior fix #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ async function fetchProblemLanguage(): Promise<string | undefined> {
if (defaultLanguage && languages.indexOf(defaultLanguage) < 0) {
defaultLanguage = undefined;
}
const language: string | undefined = defaultLanguage || await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use" });
const language: string | undefined = defaultLanguage || await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use", ignoreFocusOut: true });
// fire-and-forget default language query
(async (): Promise<void> => {
if (!defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
if (language && !defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
`Would you like to set '${language}' as your default language?`,
DialogOptions.yes,
Expand Down
9 changes: 8 additions & 1 deletion src/leetCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ class LeetCodeExecutor {
}

public async submitSolution(filePath: string): Promise<string> {
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
try {
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
} catch (error) {
if (error.result) {
return error.result;
}
throw error;
}
}

public async testSolution(filePath: string, testString?: string): Promise<string> {
Expand Down
11 changes: 10 additions & 1 deletion src/utils/cpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import * as cp from "child_process";
import * as vscode from "vscode";
import { leetCodeChannel } from "../leetCodeChannel";

interface IExecError extends Error {
result?: string;
}

export async function executeCommand(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
return new Promise((resolve: (res: string) => void, reject: (e: Error) => void): void => {
let result: string = "";
Expand All @@ -20,9 +24,14 @@ export async function executeCommand(command: string, args: string[], options: c
childProc.stderr.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));

childProc.on("error", reject);

childProc.on("close", (code: number) => {
if (code !== 0 || result.indexOf("ERROR") > -1) {
reject(new Error(`Command "${command} ${args.toString()}" failed with exit code "${code}".`));
const error: IExecError = new Error(`Command "${command} ${args.toString()}" failed with exit code "${code}".`);
if (result) {
error.result = result; // leetcode-cli may print useful content by exit with error code
}
reject(error);
} else {
resolve(result);
}
Expand Down