Skip to content

add switchDefaultLanguage #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"onCommand:leetcode.searchProblem",
"onCommand:leetcode.testSolution",
"onCommand:leetcode.submitSolution",
"onCommand:leetcode.switchDefaultLanguage",
"onView:leetCodeExplorer"
],
"main": "./out/src/extension",
Expand All @@ -55,6 +56,11 @@
"dark": "resources/dark/endpoint.svg"
}
},
{
"command": "leetcode.switchDefaultLanguage",
"title": "Switch Default Language",
"category": "LeetCode"
},
{
"command": "leetcode.signin",
"title": "Sign In",
Expand Down
11 changes: 10 additions & 1 deletion src/commands/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { IQuickItemEx } from "../shared";
import { Endpoint } from "../shared";
import { Endpoint, languages } from "../shared";
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { deleteCache } from "./cache";

export async function switchDefaultLanguage(): Promise<void> {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is somehow duplicated with https://github.com/jdneo/vscode-leetcode/blob/master/src/commands/show.ts#L44-L51

Can we extract them out to share only one piece of code?

const language: string | undefined = await vscode.window.showQuickPick(languages, { placeHolder: "Select the language you want to use" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user has already set a default language, we should at least add a ✅mark before the language.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it later for I am going to change my job these days.

if (!language) {
return;
}
leetCodeConfig.update("defaultLanguage", language, true);
}

export async function switchEndpoint(): Promise<void> {
const isCnEnabled: boolean = getLeetCodeEndpoint() === Endpoint.LeetCodeCN;
const picks: Array<IQuickItemEx<string>> = [];
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
vscode.commands.registerCommand("leetcode.testSolution", (uri?: vscode.Uri) => test.testSolution(uri)),
vscode.commands.registerCommand("leetcode.submitSolution", (uri?: vscode.Uri) => submit.submitSolution(uri)),
vscode.commands.registerCommand("leetcode.switchDefaultLanguage", () => plugin.switchDefaultLanguage()),
);

await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint());
Expand Down