Skip to content

Commit b8b91a6

Browse files
author
chengruilin
committed
feat: 下载题目的时候根据 tag 进行分类
1 parent b7b8e50 commit b8b91a6

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
<img src="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/pick_problem.png" alt="Pick a Problem" />
6868
</p>
6969

70-
- Right click the problem in the `LeetCode Explorer` and select `Show Problem` will generate a new file with the problem description for you.
70+
- Right click the problem in the `LeetCode Explorer` and select `Show problem` will generate a new file with the problem description for you.
71+
- Right click the problem in the `LeetCode Explorer` and select `Show problem with tag` will generate a new file with the problem description and classified by tag folder.
7172

7273
> Note: If no folder is opened in VS Code, the extension will save the problem files in **$HOME/.leetcode/**.
7374
@@ -114,13 +115,13 @@
114115

115116

116117
## Settings
117-
| Setting Name | Description | Default Value |
118-
|---|---|---|
119-
| `leetcode.hideSolved` | Specify to hide the solved problems or not | `false` |
120-
| `leetcode.showLocked` | Specify to show the locked problems or not. Only Premium users could open the locked problems | `false` |
121-
| `leetcode.defaultLanguage` | Specify the default language used to solve the problem. Supported languages are: `bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `python`,`python3`,`ruby`,`scala`,`swift` | `N/A` |
122-
| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
123-
| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
118+
| Setting Name | Description | Default Value |
119+
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
120+
| `leetcode.hideSolved` | Specify to hide the solved problems or not | `false` |
121+
| `leetcode.showLocked` | Specify to show the locked problems or not. Only Premium users could open the locked problems | `false` |
122+
| `leetcode.defaultLanguage` | Specify the default language used to solve the problem. Supported languages are: `bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `python`,`python3`,`ruby`,`scala`,`swift` | `N/A` |
123+
| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
124+
| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
124125

125126
## Release Notes
126127

docs/README_zh-CN.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
<img src="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/pick_problem.png" alt="选择题目" />
6868
</p>
6969

70-
-`LeetCode Explorer`**右键**题目并选择 `Show Problem` 进行答题。
70+
-`LeetCode Explorer`**右键**题目并选择 `Show problem` 进行答题。
71+
-`LeetCode Explorer`**右键**题目并选择 `Show problem with tag`,题目会被放进分类好的文件夹,并进行答题。
7172

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

115116

116117
## 插件配置项
117-
| 配置项名称 | 描述 | 默认值 |
118-
|---|---|---|
119-
| `leetcode.hideSolved` | 指定是否要隐藏已解决的问题 | `false` |
120-
| `leetcode.showLocked` | 指定是否显示付费题目,只有付费账户才可以打开付费题目 | `false` |
121-
| `leetcode.defaultLanguage` | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `python`,`python3`,`ruby`,`scala`,`swift` | `N/A` |
122-
| `leetcode.useWsl` | 指定是否启用 WSL | `false` |
123-
| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
118+
| 配置项名称 | 描述 | 默认值 |
119+
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
120+
| `leetcode.hideSolved` | 指定是否要隐藏已解决的问题 | `false` |
121+
| `leetcode.showLocked` | 指定是否显示付费题目,只有付费账户才可以打开付费题目 | `false` |
122+
| `leetcode.defaultLanguage` | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `python`,`python3`,`ruby`,`scala`,`swift` | `N/A` |
123+
| `leetcode.useWsl` | 指定是否启用 WSL | `false` |
124+
| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
124125

125126
## 更新日志
126127

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
"title": "Show Problem",
9494
"category": "LeetCode"
9595
},
96+
{
97+
"command": "leetcode.showProblemWithTag",
98+
"title": "Show problem with tag",
99+
"category": "LeetCode"
100+
},
96101
{
97102
"command": "leetcode.searchProblem",
98103
"title": "Search Problem",
@@ -158,6 +163,11 @@
158163
"command": "leetcode.showProblem",
159164
"when": "view == leetCodeExplorer && viewItem == problem",
160165
"group": "leetcode@1"
166+
},
167+
{
168+
"command": "leetcode.showProblemWithTag",
169+
"when": "view == leetCodeExplorer && viewItem == problem",
170+
"group": "leetcode@1"
161171
}
162172
],
163173
"commandPalette": [

src/commands/show.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { selectWorkspaceFolder } from "../utils/workspaceUtils";
1212
import * as wsl from "../utils/wslUtils";
1313
import * as list from "./list";
1414

15-
export async function showProblem(node?: LeetCodeNode): Promise<void> {
15+
export async function showProblem(node?: LeetCodeNode, withTagFloder?: boolean): Promise<void> {
1616
if (!node) {
1717
return;
1818
}
19-
await showProblemInternal(node.id);
19+
await showProblemInternal(node.id, withTagFloder);
2020
}
2121

2222
export async function searchProblem(): Promise<void> {
@@ -37,7 +37,7 @@ export async function searchProblem(): Promise<void> {
3737
await showProblemInternal(choice.value);
3838
}
3939

40-
async function showProblemInternal(id: string): Promise<void> {
40+
async function showProblemInternal(id: string, withTagFloder?: boolean): Promise<void> {
4141
try {
4242
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
4343
let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
@@ -49,7 +49,11 @@ async function showProblemInternal(id: string): Promise<void> {
4949
return;
5050
}
5151

52-
const outDir: string = await selectWorkspaceFolder();
52+
let outDir: string = await selectWorkspaceFolder();
53+
if (withTagFloder) {
54+
const { tags } = await leetCodeExecutor.getCompaniesAndTags();
55+
outDir = `${outDir}/${tags[id][0].split("-").map((c: string) => c[0].toUpperCase() + c.slice(1)).join(" ")}`;
56+
}
5357
await fse.ensureDir(outDir);
5458
const result: string = await leetCodeExecutor.showProblem(id, language, outDir);
5559
const reg: RegExp = /\* Source Code:\s*(.*)/;

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
4343
vscode.commands.registerCommand("leetcode.selectSessions", () => session.selectSession()),
4444
vscode.commands.registerCommand("leetcode.createSession", () => session.createSession()),
4545
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
46+
vscode.commands.registerCommand("leetcode.showProblemWithTag", (node: LeetCodeNode) => show.showProblem(node, true)),
4647
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
4748
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
4849
vscode.commands.registerCommand("leetcode.testSolution", (uri?: vscode.Uri) => test.testSolution(uri)),

0 commit comments

Comments
 (0)