Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 99dcf76

Browse files
author
chengruilin
committed
feat: add outputPath config
1 parent b8b91a6 commit 99dcf76

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
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.
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.
70+
- Right click the problem in the `LeetCode Explorer` and select `Show Problem` will generate a new file with the problem description for you.
7271

7372
> Note: If no folder is opened in VS Code, the extension will save the problem files in **$HOME/.leetcode/**.
7473
@@ -122,6 +121,10 @@
122121
| `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` |
123122
| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
124123
| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
124+
| `leetcode.outputPath` | * `${tag}` - a directory based on the problem's tag. For example, if the problem belongs to: `Binary Indexed Tree`, then a folder named `binary_indexed_tree` will be used here. |
125+
* `${language}` - a directory based on the language used. For example, `java` for Java language
126+
* `${difficulty}` - a directory based on the problem's difficulty. For example, `easy`
127+
* If this setting is not set, the files will be generated to the base path of the workspace folder | `root` |
125128

126129
## Release Notes
127130

docs/README_zh-CN.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
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` 进行答题。
71-
-`LeetCode Explorer`**右键**题目并选择 `Show problem with tag`,题目会被放进分类好的文件夹,并进行答题。
70+
-`LeetCode Explorer`**右键**题目并选择 `Show Problem` 进行答题。
7271

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

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@
9393
"title": "Show Problem",
9494
"category": "LeetCode"
9595
},
96-
{
97-
"command": "leetcode.showProblemWithTag",
98-
"title": "Show problem with tag",
99-
"category": "LeetCode"
100-
},
10196
{
10297
"command": "leetcode.searchProblem",
10398
"title": "Search Problem",
@@ -163,11 +158,6 @@
163158
"command": "leetcode.showProblem",
164159
"when": "view == leetCodeExplorer && viewItem == problem",
165160
"group": "leetcode@1"
166-
},
167-
{
168-
"command": "leetcode.showProblemWithTag",
169-
"when": "view == leetCodeExplorer && viewItem == problem",
170-
"group": "leetcode@1"
171161
}
172162
],
173163
"commandPalette": [
@@ -257,6 +247,18 @@
257247
"leetcode-cn"
258248
],
259249
"description": "Endpoint of the user account."
250+
},
251+
"leetcode.outputPath": {
252+
"type": "string",
253+
"default": "root",
254+
"scope": "application",
255+
"enum": [
256+
"root",
257+
"tag",
258+
"language",
259+
"difficulty"
260+
],
261+
"description": "Specifies the relative path to save the problem files."
260262
}
261263
}
262264
}

src/commands/show.ts

Lines changed: 20 additions & 6 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, withTagFloder?: boolean): Promise<void> {
15+
export async function showProblem(node?: LeetCodeNode): Promise<void> {
1616
if (!node) {
1717
return;
1818
}
19-
await showProblemInternal(node.id, withTagFloder);
19+
await showProblemInternal(node.id);
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, withTagFloder?: boolean): Promise<void> {
40+
async function showProblemInternal(id: string): Promise<void> {
4141
try {
4242
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
4343
let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
@@ -50,9 +50,23 @@ async function showProblemInternal(id: string, withTagFloder?: boolean): Promise
5050
}
5151

5252
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(" ")}`;
53+
const outputPath: string = leetCodeConfig.get<string>("outputPath") || "root";
54+
switch (outputPath) {
55+
case "root": {
56+
break;
57+
}
58+
case "tag": {
59+
const { tags } = await leetCodeExecutor.getCompaniesAndTags();
60+
outDir = `${outDir}/${tags[id][0].split("-").map((c: string) => c[0].toUpperCase() + c.slice(1)).join("")}`;
61+
break;
62+
}
63+
case "language": {
64+
outDir = `${outDir}/${language}`;
65+
break;
66+
}
67+
case "difficulty": {
68+
break;
69+
}
5670
}
5771
await fse.ensureDir(outDir);
5872
const result: string = await leetCodeExecutor.showProblem(id, language, outDir);

src/extension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ 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)),
4746
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
4847
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
4948
vscode.commands.registerCommand("leetcode.testSolution", (uri?: vscode.Uri) => test.testSolution(uri)),

0 commit comments

Comments
 (0)