Skip to content

Commit 40c7f4b

Browse files
authored
Merge pull request LeetCode-OpenSource#7 from jdneo/cs/defaultlanguage
Cs/defaultlanguage
2 parents 142b36c + 83416f8 commit 40c7f4b

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

package.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,41 @@
118118
"when": "never"
119119
}
120120
]
121-
}
121+
},
122+
"configuration": [
123+
{
124+
"title": "LeetCode",
125+
"properties": {
126+
"leetcode.defaultLanguage": {
127+
"type": "string",
128+
"enum": [
129+
"bash",
130+
"c",
131+
"cpp",
132+
"csharp",
133+
"golang",
134+
"java",
135+
"javascript",
136+
"kotlin",
137+
"mysql",
138+
"python",
139+
"python3",
140+
"ruby",
141+
"scala",
142+
"swift"
143+
],
144+
"scope": "window",
145+
"description": "Default language preference for solving the problems."
146+
},
147+
"leetcode.showSetDefaultLanguageHint": {
148+
"type": "boolean",
149+
"default": true,
150+
"scope": "window",
151+
"description": "Show a hint to let user set the default language preference."
152+
}
153+
}
154+
}
155+
]
122156
},
123157
"scripts": {
124158
"vscode:prepublish": "npm run compile",

src/commands/show.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LeetCodeNode } from "../leetCodeExplorer";
66
import { leetCodeManager } from "../leetCodeManager";
77
import { IQuickItemEx, languages, leetCodeBinaryPath } from "../shared";
88
import { executeCommand } from "../utils/cpUtils";
9-
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
9+
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
1010
import { selectWorkspaceFolder } from "../utils/workspaceUtils";
1111
import * as list from "./list";
1212

@@ -37,10 +37,28 @@ export async function searchProblem(channel: vscode.OutputChannel): Promise<void
3737

3838
async function showProblemInternal(channel: vscode.OutputChannel, id: string): Promise<void> {
3939
try {
40-
const language: string | undefined = await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use" });
40+
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
41+
let defaultLanguage = leetCodeConfig.get<string>("defaultLanguage");
42+
if (defaultLanguage && languages.indexOf(defaultLanguage) < 0) {
43+
defaultLanguage = undefined;
44+
}
45+
const language: string | undefined = defaultLanguage || await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use" });
4146
if (!language) {
4247
return;
4348
}
49+
if (!defaultLanguage && leetCodeConfig.get<boolean>("showSetDefaultLanguageHint")) {
50+
const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
51+
`Would you like to set '${language}' as your default language?`,
52+
DialogOptions.yes,
53+
DialogOptions.no,
54+
DialogOptions.never,
55+
);
56+
if (choice === DialogOptions.yes) {
57+
leetCodeConfig.update("defaultLanguage", language, true /* UserSetting */);
58+
} else if (choice === DialogOptions.never) {
59+
leetCodeConfig.update("showSetDefaultLanguageHint", false, true /* UserSetting */);
60+
}
61+
}
4462
const outdir: string = await selectWorkspaceFolder();
4563
await fse.ensureDir(outdir);
4664
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", outdir]);

src/utils/uiUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export namespace DialogOptions {
77
export const open: vscode.MessageItem = { title: "Open" };
88
export const yes: vscode.MessageItem = { title: "Yes" };
99
export const no: vscode.MessageItem = { title: "No", isCloseAffordance: true };
10+
export const never: vscode.MessageItem = { title: "Never" };
1011
export const singUp: vscode.MessageItem = { title: "Sign up" };
1112
}
1213

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