Skip to content

Commit feae070

Browse files
sheche@microsoft.comsheche@microsoft.com
authored andcommitted
prompt set default language at the end of show command
1 parent 3a0a0cb commit feae070

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/commands/show.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
4646
if (!language) {
4747
return;
4848
}
49+
50+
const outdir: string = await selectWorkspaceFolder();
51+
await fse.ensureDir(outdir);
52+
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", outdir]);
53+
const reg: RegExp = /\* Source Code:\s*(.*)/;
54+
const match: RegExpMatchArray | null = result.match(reg);
55+
if (match && match.length >= 2) {
56+
await vscode.window.showTextDocument(vscode.Uri.file(match[1].trim()), { preview: false });
57+
} else {
58+
throw new Error("Failed to fetch the problem information");
59+
}
60+
4961
if (!defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
5062
const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
5163
`Would you like to set '${language}' as your default language?`,
@@ -59,16 +71,6 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
5971
leetCodeConfig.update("showSetDefaultLanguageHint", false, true /* UserSetting */);
6072
}
6173
}
62-
const outdir: string = await selectWorkspaceFolder();
63-
await fse.ensureDir(outdir);
64-
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", outdir]);
65-
const reg: RegExp = /\* Source Code:\s*(.*)/;
66-
const match: RegExpMatchArray | null = result.match(reg);
67-
if (match && match.length >= 2) {
68-
await vscode.window.showTextDocument(vscode.Uri.file(match[1].trim()), { preview: false });
69-
} else {
70-
throw new Error("Failed to fetch the problem information");
71-
}
7274
} catch (error) {
7375
await promptForOpenOutputChannel("Failed to fetch the problem information. Please open the output channel for details", DialogType.error, channel);
7476
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy