diff --git a/package.json b/package.json index 9f57bfcd..29f1226c 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,41 @@ "when": "never" } ] - } + }, + "configuration": [ + { + "title": "LeetCode", + "properties": { + "leetcode.defaultLanguage": { + "type": "string", + "enum": [ + "bash", + "c", + "cpp", + "csharp", + "golang", + "java", + "javascript", + "kotlin", + "mysql", + "python", + "python3", + "ruby", + "scala", + "swift" + ], + "scope": "window", + "description": "Default language preference for solving the problems." + }, + "leetcode.showSetDefaultLanguageHint": { + "type": "boolean", + "default": true, + "scope": "window", + "description": "Show a hint to let user set the default language preference." + } + } + } + ] }, "scripts": { "vscode:prepublish": "npm run compile", diff --git a/src/commands/show.ts b/src/commands/show.ts index 2f0cfffd..100a1929 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -6,7 +6,7 @@ import { LeetCodeNode } from "../leetCodeExplorer"; import { leetCodeManager } from "../leetCodeManager"; import { IQuickItemEx, languages, leetCodeBinaryPath } from "../shared"; import { executeCommand } from "../utils/cpUtils"; -import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils"; +import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils"; import { selectWorkspaceFolder } from "../utils/workspaceUtils"; import * as list from "./list"; @@ -37,10 +37,28 @@ export async function searchProblem(channel: vscode.OutputChannel): Promise { try { - const language: string | undefined = await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use" }); + const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); + let defaultLanguage = leetCodeConfig.get("defaultLanguage"); + 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" }); if (!language) { return; } + if (!defaultLanguage && leetCodeConfig.get("showSetDefaultLanguageHint")) { + const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage( + `Would you like to set '${language}' as your default language?`, + DialogOptions.yes, + DialogOptions.no, + DialogOptions.never, + ); + if (choice === DialogOptions.yes) { + leetCodeConfig.update("defaultLanguage", language, true /* UserSetting */); + } else if (choice === DialogOptions.never) { + leetCodeConfig.update("showSetDefaultLanguageHint", false, true /* UserSetting */); + } + } const outdir: string = await selectWorkspaceFolder(); await fse.ensureDir(outdir); const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", outdir]); diff --git a/src/utils/uiUtils.ts b/src/utils/uiUtils.ts index 265a9cf9..b1e804e9 100644 --- a/src/utils/uiUtils.ts +++ b/src/utils/uiUtils.ts @@ -7,6 +7,7 @@ export namespace DialogOptions { export const open: vscode.MessageItem = { title: "Open" }; export const yes: vscode.MessageItem = { title: "Yes" }; export const no: vscode.MessageItem = { title: "No", isCloseAffordance: true }; + export const never: vscode.MessageItem = { title: "Never" }; export const singUp: vscode.MessageItem = { title: "Sign up" }; } 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