Skip to content

workspaceFolder 可以尝试从环境变量中读取数据 #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
## version 2.19.10

- workspaceFolder 可以尝试从环境变量中读取数据
- 例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值
- 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode

## version 2.19.9

- 146题非Solution类时cpp调试报错
- 146 题非 Solution 类时 cpp 调试报错

## version 2.19.8

- 新增尊享100分类
- 新增尊享 100 分类

## version 2.19.7

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
| <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` |
| <font color=red>leetcode-problem-rating.useWsl</font> | 指定是否启用 WSL | `false` |
| <font color=red>leetcode-problem-rating.endpoint</font> | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | <font color=red>leetcode.cn</font> |
| <font color=red>leetcode-problem-rating.workspaceFolder</font> | 指定保存文件的工作区目录 | `""` |
| <font color=red>leetcode-problem-rating.workspaceFolder</font> | 指定保存文件的工作区目例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值, 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode 录 | `""` |
| <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}格式 | |
| <font color=red>leetcode-problem-rating.enableStatusBar</font> | 指定是否在 VS Code 下方显示插件状态栏。 <font color=red>增加周赛分数据</font> | `true` |
| <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> |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "%main.description%",
"version": "2.19.9",
"version": "2.19.10",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down
20 changes: 19 additions & 1 deletion src/utils/ConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useWsl, toWslPath } from "../utils/SystemUtils";
import * as path from "path";
import * as fse from "fs-extra";
import * as os from "os";
import { logOutput } from "./OutputUtils";

// vscode的配置
export function getVsCodeConfig(): WorkspaceConfiguration {
Expand Down Expand Up @@ -87,7 +88,24 @@ export function getPickOneByRankRangeMax(): number {
}
// 工作目录
export function getWorkspaceFolder(): string {
return getVsCodeConfig().get<string>("workspaceFolder", "");
let cur_wsf = getVsCodeConfig().get<string>("workspaceFolder", "");
return resolveWorkspaceFolder(cur_wsf);
}

// 尝试从环境变量解析WorkspaceFolder
function resolveWorkspaceFolder(cur_wsf: string): string {
return cur_wsf.replace(/\$\{(.*?)\}/g, (_substring: string, ...args: string[]) => {
const placeholder: string = args[0].trim();
switch (placeholder) {
default:
if (process.env[placeholder]) {
return process.env[placeholder] || "";
} else {
logOutput.append("环境变量" + JSON.stringify(process.env));
throw new Error(`无法从环境变量获取到${placeholder}的变量, 请查看控制台信息~ `);
}
}
});
}

// 快捷操作
Expand Down