diff --git a/README.md b/README.md
index ab08b3b2..64f62c19 100644
--- a/README.md
+++ b/README.md
@@ -140,7 +140,7 @@
| `leetcode.defaultLanguage` | Specify the default language used to solve the problem. Supported languages are: `bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`,`rust`, `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.outputFolder` | Specify the relative path to save the problem files. Besides using customized path, there are also several reserved words which can be used here:
- `${tag}`: Categorize the problem according to their tags.
- `${language}`: Categorize the problem according to their language.
- `${difficulty}`: Categorize the problem according to their difficulty.
| N/A |
+| `leetcode.outputFolder` | Specify the relative path to save the problem files. Besides using customized path, there are also several reserved words which can be used here: - `${tag}`: Categorize the problem according to their tags.
- `${language}`: Categorize the problem according to their language.
- `${difficulty}`: Categorize the problem according to their difficulty.
For example: `problem-${tag}-${difficulty}` | N/A |
| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` |
| `leetcode.enableShortcuts` | Specify whether the submit and test shortcuts in editor or not. | `true` |
| `leetcode.enableSideMode` | Specify whether `preview`, `solution` and `submission` tab should be grouped into the second editor column when solving a problem. | `true` |
diff --git a/docs/README_zh-CN.md b/docs/README_zh-CN.md
index 98b04748..39ae2683 100644
--- a/docs/README_zh-CN.md
+++ b/docs/README_zh-CN.md
@@ -140,7 +140,7 @@
| `leetcode.defaultLanguage` | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`,`swift` | `N/A` |
| `leetcode.useWsl` | 指定是否启用 WSL | `false` |
| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
-| `leetcode.outputFolder` | 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:- `${tag}`: 根据题目的类别进行分类。
- `${language}`: 根据题目的语言进行分类。
- `${difficulty}`: 根据题目的难度进行分类。
| N/A |
+| `leetcode.outputFolder` | 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:- `${tag}`: 根据题目的类别进行分类。
- `${language}`: 根据题目的语言进行分类。
- `${difficulty}`: 根据题目的难度进行分类。
例如:`problem-${tag}-${difficulty}` | N/A |
| `leetcode.enableStatusBar` | 指定是否在 VS Code 下方显示插件状态栏。 | `true` |
| `leetcode.enableShortcuts` | 指定是否在 VS Code 编辑文件下方显示提交和测试的快捷按钮。 | `true` |
| `leetcode.enableSideMode` | 指定在解决一道题时,是否将`问题预览`、`高票答案`与`提交结果`窗口集中在编辑器的第二栏。 | `true` |
diff --git a/src/commands/show.ts b/src/commands/show.ts
index 77256dbf..6277241f 100644
--- a/src/commands/show.ts
+++ b/src/commands/show.ts
@@ -107,14 +107,12 @@ async function showProblemInternal(node: IProblem): Promise {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
let outDir: string = await selectWorkspaceFolder();
let relativePath: string = (leetCodeConfig.get("outputFolder", "")).trim();
- const matchResult: RegExpMatchArray | null = relativePath.match(/\$\{(.*?)\}/);
- if (matchResult) {
- const resolvedPath: string | undefined = await resolveRelativePath(matchResult[1].toLocaleLowerCase(), node, language);
- if (!resolvedPath) {
+ if (relativePath) {
+ relativePath = await resolveRelativePath(relativePath, node, language);
+ if (!relativePath) {
leetCodeChannel.appendLine("Showing problem canceled by user.");
return;
}
- relativePath = resolvedPath;
}
outDir = path.join(outDir, relativePath);
@@ -166,27 +164,39 @@ function parseProblemDecorator(state: ProblemState, locked: boolean): string {
}
}
-async function resolveRelativePath(value: string, node: IProblem, selectedLanguage: string): Promise {
- switch (value) {
- case "tag":
- if (node.tags.length === 1) {
- return node.tags[0];
- }
- return await vscode.window.showQuickPick(
- node.tags,
- {
- matchOnDetail: true,
- placeHolder: "Multiple tags available, please select one",
- ignoreFocusOut: true,
- },
- );
- case "language":
- return selectedLanguage;
- case "difficulty":
- return node.difficulty;
- default:
- const errorMsg: string = `The config '${value}' is not supported.`;
- leetCodeChannel.appendLine(errorMsg);
- throw new Error(errorMsg);
+async function resolveRelativePath(relativePath: string, node: IProblem, selectedLanguage: string): Promise {
+ if (/\$\{tag\}/i.test(relativePath)) {
+ const tag: string | undefined = await resolveTagForProblem(node);
+ if (!tag) {
+ return "";
+ }
+ relativePath = relativePath.replace(/\$\{tag\}/ig, tag);
}
+
+ relativePath = relativePath.replace(/\$\{language\}/ig, selectedLanguage);
+ relativePath = relativePath.replace(/\$\{difficulty\}/ig, node.difficulty.toLocaleLowerCase());
+
+ // Check if there is any unsupported configuration
+ const matchResult: RegExpMatchArray | null = relativePath.match(/\$\{(.*?)\}/);
+ if (matchResult && matchResult.length >= 1) {
+ const errorMsg: string = `The config '${matchResult[1]}' is not supported.`;
+ leetCodeChannel.appendLine(errorMsg);
+ throw new Error(errorMsg);
+ }
+
+ return relativePath;
+}
+
+async function resolveTagForProblem(problem: IProblem): Promise {
+ if (problem.tags.length === 1) {
+ return problem.tags[0];
+ }
+ return await vscode.window.showQuickPick(
+ problem.tags,
+ {
+ matchOnDetail: true,
+ placeHolder: "Multiple tags available, please select one",
+ ignoreFocusOut: true,
+ },
+ );
}