Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add a new command to support switching the default language#178

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 1 commit intomasterfromcs/switch
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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
4 changes: 4 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,10 @@ All notable changes to the "leetcode" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.12.0]
## Added
- Add new command `LeetCode: Switch Default Language` to support switching the default language [#115](https://github.com/jdneo/vscode-leetcode/issues/115)

## [0.11.0]
## Added
- Add new setting: `leetcode.outputFolder` to customize the sub-directory to save the files generated by 'Show Problem' [#119](https://github.com/jdneo/vscode-leetcode/issues/119)
Expand Down
2 changes: 2 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,8 @@

> Note: If no folder is opened in VS Code, the extension will save the problem files in **$HOME/.leetcode/**.

> You can switch the default language by triggering the command: `LeetCode: Switch Default Language`.

---

### Submit the Answer
Expand Down
2 changes: 2 additions & 0 deletionsdocs/README_zh-CN.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,8 @@

> 注意:若当前 VS Code 没有已打开的文件夹,则生成的题目文件会存储于 **$HOME/.leetcode/** 目录下。

> 注意:你可以通过 `LeetCode: Switch Default Language` 命令变更答题时默认使用编程语言。

---

### 提交答案
Expand Down
6 changes: 6 additions & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand Up@@ -111,6 +112,11 @@
"command": "leetcode.submitSolution",
"title": "Submit to LeetCode",
"category": "LeetCode"
},
{
"command": "leetcode.switchDefaultLanguage",
"title": "Switch Default Language",
"category": "LeetCode"
}
],
"viewsContainers": {
Expand Down
38 changes: 38 additions & 0 deletionssrc/commands/language.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import { QuickPickItem, window, workspace, WorkspaceConfiguration } from "vscode";
import { languages } from "../shared";

export async function switchDefaultLanguage(): Promise<void> {
const leetCodeConfig: WorkspaceConfiguration = workspace.getConfiguration("leetcode");
const defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
const languageItems: QuickPickItem[] = [];
for (const language of languages) {
languageItems.push({
label: language,
description: defaultLanguage === language ? "Currently used" : undefined,
});
}
// Put the default language at the top of the list
languageItems.sort((a: QuickPickItem, b: QuickPickItem) => {
if (a.description) {
return Number.MIN_SAFE_INTEGER;
} else if (b.description) {
return Number.MAX_SAFE_INTEGER;
}
return a.label.localeCompare(b.label);
});

const selectedItem: QuickPickItem | undefined = await window.showQuickPick(languageItems, {
placeHolder: "Please the default language",
ignoreFocusOut: true,
});

if (!selectedItem) {
return;
}

leetCodeConfig.update("defaultLanguage", selectedItem.label, true /* Global */);
window.showInformationMessage(`Successfully set the default language to ${selectedItem.label}`);
}
2 changes: 2 additions & 0 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
import * as vscode from "vscode";
import { codeLensProvider } from "./codeLensProvider";
import * as cache from "./commands/cache";
import { switchDefaultLanguage } from "./commands/language";
import * as plugin from "./commands/plugin";
import * as session from "./commands/session";
import * as show from "./commands/show";
Expand DownExpand Up@@ -47,6 +48,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", () => switchDefaultLanguage()),
);

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

[8]ページ先頭

©2009-2025 Movatter.jp