Skip to content

Commit cc75d5d

Browse files
authored
Merge pull request #232 from ccagml/main
workspaceFolder 可以尝试从环境变量中读取数据
2 parents bcc71fa + b9917b8 commit cc75d5d

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
## version 2.19.10
2+
3+
- workspaceFolder 可以尝试从环境变量中读取数据
4+
- 例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值
5+
- 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode
6+
17
## version 2.19.9
28

3-
- 146题非Solution类时cpp调试报错
9+
- 146 题非 Solution 类时 cpp 调试报错
410

511
## version 2.19.8
612

7-
- 新增尊享100分类
13+
- 新增尊享 100 分类
814

915
## version 2.19.7
1016

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
| <font color=red>leetcode-problem-rating.defaultLanguage</font> | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`, `swift`, `typescript` | `N/A` |
207207
| <font color=red>leetcode-problem-rating.useWsl</font> | 指定是否启用 WSL | `false` |
208208
| <font color=red>leetcode-problem-rating.endpoint</font> | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | <font color=red>leetcode.cn</font> |
209-
| <font color=red>leetcode-problem-rating.workspaceFolder</font> | 指定保存文件的工作区目录 | `""` |
209+
| <font color=red>leetcode-problem-rating.workspaceFolder</font> | 指定保存文件的工作区目例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值, 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode 录 | `""` |
210210
| <font color=red>leetcode-problem-rating.filePath</font> | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%98%E7%9B%AE%E6%96%87%E4%BB%B6%E7%9A%84%E7%9B%B8%E5%AF%B9%E6%96%87%E4%BB%B6%E5%A4%B9%E8%B7%AF%E5%BE%84%E5%92%8C%E6%96%87%E4%BB%B6%E5%90%8D)。 额外拓展\${yyyymmdd}、${timestamp}格式 | |
211211
| <font color=red>leetcode-problem-rating.enableStatusBar</font> | 指定是否在 VS Code 下方显示插件状态栏。 <font color=red>增加周赛分数据</font> | `true` |
212212
| <font color=red>leetcode-problem-rating.editor.shortcuts</font> | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `star`, `solution`, `description`, <font color=red>case</font>, <font color=red>allcase</font> 。 | <font color=red>["submit, case, allcase, test, solution"]</font> |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "2.19.9",
5+
"version": "2.19.10",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",

src/utils/ConfigUtils.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { useWsl, toWslPath } from "../utils/SystemUtils";
3434
import * as path from "path";
3535
import * as fse from "fs-extra";
3636
import * as os from "os";
37+
import { logOutput } from "./OutputUtils";
3738

3839
// vscode的配置
3940
export function getVsCodeConfig(): WorkspaceConfiguration {
@@ -87,7 +88,24 @@ export function getPickOneByRankRangeMax(): number {
8788
}
8889
// 工作目录
8990
export function getWorkspaceFolder(): string {
90-
return getVsCodeConfig().get<string>("workspaceFolder", "");
91+
let cur_wsf = getVsCodeConfig().get<string>("workspaceFolder", "");
92+
return resolveWorkspaceFolder(cur_wsf);
93+
}
94+
95+
// 尝试从环境变量解析WorkspaceFolder
96+
function resolveWorkspaceFolder(cur_wsf: string): string {
97+
return cur_wsf.replace(/\$\{(.*?)\}/g, (_substring: string, ...args: string[]) => {
98+
const placeholder: string = args[0].trim();
99+
switch (placeholder) {
100+
default:
101+
if (process.env[placeholder]) {
102+
return process.env[placeholder] || "";
103+
} else {
104+
logOutput.append("环境变量" + JSON.stringify(process.env));
105+
throw new Error(`无法从环境变量获取到${placeholder}的变量, 请查看控制台信息~ `);
106+
}
107+
}
108+
});
91109
}
92110

93111
// 快捷操作

0 commit comments

Comments
 (0)