Skip to content
Prev Previous commit
Next Next commit
feat: add outputPath config
  • Loading branch information
chengruilin committed Feb 13, 2019
commit 99dcf76dc71287ecd2ea00b158db6eaf7d5da522
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
<img src="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/pick_problem.png" alt="Pick a Problem" />
</p>

- Right click the problem in the `LeetCode Explorer` and select `Show problem` will generate a new file with the problem description for you.
- 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.
- Right click the problem in the `LeetCode Explorer` and select `Show Problem` will generate a new file with the problem description for you.

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

Expand Down Expand Up @@ -122,6 +121,10 @@
| `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` |
| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
| `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. |
* `${language}` - a directory based on the language used. For example, `java` for Java language
* `${difficulty}` - a directory based on the problem's difficulty. For example, `easy`
* If this setting is not set, the files will be generated to the base path of the workspace folder | `root` |

## Release Notes

Expand Down
3 changes: 1 addition & 2 deletions docs/README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
<img src="https://raw.githubusercontent.com/jdneo/vscode-leetcode/master/docs/imgs/pick_problem.png" alt="选择题目" />
</p>

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

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

Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@
"title": "Show Problem",
"category": "LeetCode"
},
{
"command": "leetcode.showProblemWithTag",
"title": "Show problem with tag",
"category": "LeetCode"
},
{
"command": "leetcode.searchProblem",
"title": "Search Problem",
Expand Down Expand Up @@ -163,11 +158,6 @@
"command": "leetcode.showProblem",
"when": "view == leetCodeExplorer && viewItem == problem",
"group": "leetcode@1"
},
{
"command": "leetcode.showProblemWithTag",
"when": "view == leetCodeExplorer && viewItem == problem",
"group": "leetcode@1"
}
],
"commandPalette": [
Expand Down Expand Up @@ -257,6 +247,18 @@
"leetcode-cn"
],
"description": "Endpoint of the user account."
},
"leetcode.outputPath": {
"type": "string",
"default": "root",
"scope": "application",
"enum": [
"root",
"tag",
"language",
"difficulty"
],
"description": "Specifies the relative path to save the problem files."
}
}
}
Expand Down
26 changes: 20 additions & 6 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { selectWorkspaceFolder } from "../utils/workspaceUtils";
import * as wsl from "../utils/wslUtils";
import * as list from "./list";

export async function showProblem(node?: LeetCodeNode, withTagFloder?: boolean): Promise<void> {
export async function showProblem(node?: LeetCodeNode): Promise<void> {
if (!node) {
return;
}
await showProblemInternal(node.id, withTagFloder);
await showProblemInternal(node.id);
}

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

async function showProblemInternal(id: string, withTagFloder?: boolean): Promise<void> {
async function showProblemInternal(id: string): Promise<void> {
try {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
Expand All @@ -50,9 +50,23 @@ async function showProblemInternal(id: string, withTagFloder?: boolean): Promise
}

let outDir: string = await selectWorkspaceFolder();
if (withTagFloder) {
const { tags } = await leetCodeExecutor.getCompaniesAndTags();
outDir = `${outDir}/${tags[id][0].split("-").map((c: string) => c[0].toUpperCase() + c.slice(1)).join(" ")}`;
const outputPath: string = leetCodeConfig.get<string>("outputPath") || "root";
switch (outputPath) {
case "root": {
break;
}
case "tag": {
const { tags } = await leetCodeExecutor.getCompaniesAndTags();
outDir = `${outDir}/${tags[id][0].split("-").map((c: string) => c[0].toUpperCase() + c.slice(1)).join("")}`;
break;
}
case "language": {
outDir = `${outDir}/${language}`;
break;
}
case "difficulty": {
break;
}
}
await fse.ensureDir(outDir);
const result: string = await leetCodeExecutor.showProblem(id, language, outDir);
Expand Down
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.selectSessions", () => session.selectSession()),
vscode.commands.registerCommand("leetcode.createSession", () => session.createSession()),
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
vscode.commands.registerCommand("leetcode.showProblemWithTag", (node: LeetCodeNode) => show.showProblem(node, true)),
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
vscode.commands.registerCommand("leetcode.testSolution", (uri?: vscode.Uri) => test.testSolution(uri)),
Expand Down