From 927481a46d30813cfa0b78a732f615c24ece9380 Mon Sep 17 00:00:00 2001 From: "sheche@microsoft.com" Date: Fri, 23 Feb 2018 14:09:48 +0800 Subject: [PATCH 1/2] support setting the default language preference --- package.json | 36 +++++++++++++++++++++++++++++++++++- src/commands/show.ts | 19 +++++++++++++++++-- src/utils/uiUtils.ts | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) 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..b361db1d 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,25 @@ 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"); + const defaultLanguage = leetCodeConfig.get("defaultLanguage"); + 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" }; } From 83416f806bf8fbd9bd9acfcef4d7bfa78994393f Mon Sep 17 00:00:00 2001 From: "sheche@microsoft.com" Date: Fri, 23 Feb 2018 14:17:58 +0800 Subject: [PATCH 2/2] add check for default language --- src/commands/show.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/show.ts b/src/commands/show.ts index b361db1d..100a1929 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -38,7 +38,10 @@ export async function searchProblem(channel: vscode.OutputChannel): Promise { try { const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode"); - const defaultLanguage = leetCodeConfig.get("defaultLanguage"); + 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; 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