From ccef9aef854296aac9d46c8da0dbb222ff6f0af5 Mon Sep 17 00:00:00 2001 From: Ancient77 <76914086+Ancient77@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:06:10 +0200 Subject: [PATCH] Add second choice for unsupported default language and include --disable-extensions for extension debugging session --- .vscode/launch.json | 4 +-- src/commands/show.ts | 76 +++++++++++++++++++++++++---------------- src/leetCodeExecutor.ts | 6 ++-- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6f7862ec..8652c55e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", - "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], + "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--disable-extensions" ], "stopOnEntry": false, "sourceMaps": true, "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ], @@ -25,4 +25,4 @@ "preLaunchTask": "npm" } ] -} \ No newline at end of file +} diff --git a/src/commands/show.ts b/src/commands/show.ts index 3aebce8f..3a6df865 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -132,45 +132,61 @@ async function fetchProblemLanguage(): Promise { return language; } -async function showProblemInternal(node: IProblem): Promise { - try { - const language: string | undefined = await fetchProblemLanguage(); - if (!language) { - return; - } - - const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); - const workspaceFolder: string = await selectWorkspaceFolder(); - if (!workspaceFolder) { - return; - } +async function createPath(language:string,node:IProblem):Promise{ + const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); + const workspaceFolder: string = await selectWorkspaceFolder(); + if (!workspaceFolder) { + Promise.reject("No workspace is opened."); + } - const fileFolder: string = leetCodeConfig - .get(`filePath.${language}.folder`, leetCodeConfig.get(`filePath.default.folder`, "")) - .trim(); - const fileName: string = leetCodeConfig - .get( - `filePath.${language}.filename`, - leetCodeConfig.get(`filePath.default.filename`) || genFileName(node, language), - ) - .trim(); + const fileFolder: string = leetCodeConfig + .get(`filePath.${language}.folder`, leetCodeConfig.get(`filePath.default.folder`, "")) + .trim(); + const fileName: string = leetCodeConfig + .get( + `filePath.${language}.filename`, + leetCodeConfig.get(`filePath.default.filename`) || genFileName(node, language), + ) + .trim(); - let finalPath: string = path.join(workspaceFolder, fileFolder, fileName); + let finalPath: string = path.join(workspaceFolder, fileFolder, fileName); - if (finalPath) { - finalPath = await resolveRelativePath(finalPath, node, language); - if (!finalPath) { - leetCodeChannel.appendLine("Showing problem canceled by user."); - return; - } + if (finalPath) { + finalPath = await resolveRelativePath(finalPath, node, language); + if (!finalPath) { + leetCodeChannel.appendLine("Showing problem canceled by user."); + Promise.reject("Showing problem canceled by user."); } + } + + finalPath = wsl.useWsl() ? await wsl.toWinPath(finalPath) : finalPath; + return finalPath; +} - finalPath = wsl.useWsl() ? await wsl.toWinPath(finalPath) : finalPath; +async function showProblemInternal(node: IProblem): Promise { + try { + let language: string | undefined = await fetchProblemLanguage(); + if (!language) { + return; + } + let finalPath: string = await createPath(language,node); const descriptionConfig: IDescriptionConfiguration = settingUtils.getDescriptionConfiguration(); const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation(); + try { + await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation); + } catch (e) { + if (e instanceof Error) { + //this shows all languages, not just the ones, which are supported for this specific problem + language = await vscode.window.showQuickPick(languages, { placeHolder: "This problem is not supporting your default language, please choose another", ignoreFocusOut: true }); + if (language === undefined) { throw e; } - await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation); + finalPath = await createPath(language,node); + await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation); + } else { + throw e; + } + } const promises: any[] = [ vscode.window.showTextDocument(vscode.Uri.file(finalPath), { preview: false, viewColumn: vscode.ViewColumn.One }), promptHintMessage( diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts index d2332c7a..48a54165 100644 --- a/src/leetCodeExecutor.ts +++ b/src/leetCodeExecutor.ts @@ -107,10 +107,12 @@ class LeetCodeExecutor implements Disposable { if (!needTranslation) { cmd.push("-T"); // use -T to force English version } - + const codeTemplate: string = await this.executeCommandWithProgressEx("Fetching problem data...", this.nodeExecutable, cmd) + if(codeTemplate === undefined) { + throw new Error("language not supported"); + } if (!await fse.pathExists(filePath)) { await fse.createFile(filePath); - const codeTemplate: string = await this.executeCommandWithProgressEx("Fetching problem data...", this.nodeExecutable, cmd); await fse.writeFile(filePath, codeTemplate); } } 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