Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# version 3.1.10

- 没有分数的题目 按照 简单->绿色、中等->黄色、困难->红色 上色
- 增加配置 workspaceFolderList 当 workspaceFolder 所在目录不存在,尝试从 workspaceFolderList 获取可用目录

# version 3.1.9

- 在 Windows 上的 Python3 调试,当用例是字符串 " " 且包含空格,会使得调试参数解析错误
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
| <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> | 指定保存文件的工作区目例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值, 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode 录 | `""` |
| <font color=red>leetcode-problem-rating.workspaceFolder</font> | 指定保存文件的工作区目录例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值, 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode 录 | `""` |
| <font color=red>leetcode-problem-rating.workspaceFolderList</font> | 多个等待选择的工作区目录,如果 workspaceFolder 目录不存在,尝试从 workspaceFolderList 选取可用目录 | `["path1", "path2"]` |
| <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}对应年月日 20230720、\${timestamp}对应时间戳格式、\${cn_name}题目的中文名称 | |
| <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
8 changes: 7 additions & 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": "3.1.9",
"version": "3.1.10",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -781,6 +781,12 @@
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description%",
"default": ""
},
"leetcode-problem-rating.workspaceFolderList": {
"type": "array",
"scope": "machine",
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolderList.description%",
"default": []
},
"leetcode-problem-rating.filePath": {
"type": "object",
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.filePath.description%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"main.contributes.configuration.properties.leetcode-problem-rating.useEndpointTranslation.description": "Use endpoint's translation (if available)",
"main.contributes.configuration.properties.leetcode-problem-rating.answerDiffColor.description": "Answers are colored in different places",
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "The path of the workspace folder to store the problem files.",
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolderList.description": "workspaceFolderList",
"main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "The output folder and filename to save the problem files.",
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "Show the LeetCode status bar or not.",
"main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description": "Show the LeetCode timer bar or not.",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"main.contributes.configuration.properties.leetcode-problem-rating.useEndpointTranslation.description": "使用官网的中文翻译(如果可用)",
"main.contributes.configuration.properties.leetcode-problem-rating.answerDiffColor.description": "答案不同地方上色",
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "用于存储问题文件的工作区文件夹的路径。",
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolderList.description": "工作区文件夹待选择路径",
"main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "用于保存问题文件的输出文件夹和文件名。",
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "是否显示状态栏。",
"main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description": "是否显示计时器。",
Expand Down
1 change: 1 addition & 0 deletions src/BABA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum BabaStr {
statusBar_update = "statusBar_update",
statusBar_update_UserContestInfo = "statusBar_update_UserContestInfo",
InitFile = "InitFile",
InitWorkspaceFolder = "InitWorkspaceFolder",
LogOutputProxy = "LogOutputProxy",
LogOutputMediator = "LogOutputMediator",
BABACMD_remarkCreateNote = "BABACMD_remarkCreateNote",
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
)
);

await BABA.sendNotificationAsync(BabaStr.InitWorkspaceFolder, context);
await BABA.sendNotificationAsync(BabaStr.InitFile, context);
await BABA.sendNotificationAsync(BabaStr.InitEnv, context);
await BABA.sendNotificationAsync(BabaStr.InitLoginStatus);
Expand Down
12 changes: 12 additions & 0 deletions src/treeColor/TreeColorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ export class TreeColor implements FileDecorationProvider {
} else {
file_color.tooltip = "还没有竞赛分";
}
} else {
const difficulty: string = params.get("difficulty") || "0";
if (difficulty == "Easy") {
file_color.color = this.ITEM_COLOR.green;
file_color.tooltip = "简单难度";
} else if (difficulty == "Medium") {
file_color.color = this.ITEM_COLOR.yellow;
file_color.tooltip = "中等难度";
} else if (difficulty == "Hard") {
file_color.color = this.ITEM_COLOR.red;
file_color.tooltip = "困难难度";
}
}
return file_color;
}
Expand Down
15 changes: 14 additions & 1 deletion src/treeData/TreeDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { choiceDao } from "../dao/choiceDao";
import { tagsDao } from "../dao/tagsDao";
import { ShowMessage, promptForSignIn } from "../utils/OutputUtils";
import { BABA, BABAMediator, BABAProxy, BabaStr, BaseCC } from "../BABA";
import { getLeetCodeEndpoint, isUseEndpointTranslation, setDefaultLanguage } from "../utils/ConfigUtils";
import {
getLeetCodeEndpoint,
isUseEndpointTranslation,
selectWorkspaceFolderList,
setDefaultLanguage,
} from "../utils/ConfigUtils";
import { getNodeIdFromFile } from "../utils/SystemUtils";

export class TreeDataService implements vscode.TreeDataProvider<TreeNodeModel> {
Expand Down Expand Up @@ -45,6 +50,10 @@ export class TreeDataService implements vscode.TreeDataProvider<TreeNodeModel> {
await treeViewController.refreshCheck();
}

public async checkWorkspaceFolder() {
await selectWorkspaceFolderList();
}

public getTreeItem(element: TreeNodeModel): vscode.TreeItem | Thenable<vscode.TreeItem> {
if (element.id === "notSignIn") {
return {
Expand Down Expand Up @@ -408,6 +417,7 @@ export class TreeDataMediator extends BABAMediator {
BabaStr.BABACMD_LoginOut,
BabaStr.BABACMD_deleteAllCache,
BabaStr.QuestionData_submitNewAccept,
BabaStr.InitWorkspaceFolder,
];
}
async handleNotification(_notification: BaseCC.BaseCC.INotification) {
Expand All @@ -418,6 +428,9 @@ export class TreeDataMediator extends BABAMediator {
break;
case BabaStr.StartReadData:
break;
case BabaStr.InitWorkspaceFolder:
await treeDataService.checkWorkspaceFolder();
break;
case BabaStr.BABACMD_refresh:
case BabaStr.ConfigChange_hideScore:
case BabaStr.QuestionData_submitNewAccept:
Expand Down
92 changes: 89 additions & 3 deletions src/utils/ConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
OpenOption,
IQuickItemEx,
singleLineFlag,
OutPutType,
} from "../model/ConstDefind";

import { useWsl, toWslPath } from "../utils/SystemUtils";
Expand All @@ -36,6 +37,7 @@ import * as fse from "fs-extra";
import * as os from "os";
import { BABA, BabaStr } from "../BABA";
import { TreeNodeModel } from "../model/TreeNodeModel";
import { ShowMessage } from "./OutputUtils";

// vscode的配置
export function getVsCodeConfig(): WorkspaceConfiguration {
Expand Down Expand Up @@ -94,6 +96,17 @@ export function getWorkspaceFolder(): string {
return resolveWorkspaceFolder(cur_wsf);
}

// 工作目录
export function getWorkspaceFolderList(): Array<string> {
let cur_wsf = getVsCodeConfig().get<Array<string>>("workspaceFolderList", []);
let result: Array<string> = [];
for (let index = 0; index < cur_wsf.length; index++) {
const element = resolveWorkspaceFolder(cur_wsf[index]);
result.push(element);
}
return result;
}

// 尝试从环境变量解析WorkspaceFolder
function resolveWorkspaceFolder(cur_wsf: string): string {
return cur_wsf.replace(/\$\{(.*?)\}/g, (_substring: string, ...args: string[]) => {
Expand Down Expand Up @@ -282,8 +295,8 @@ export async function determineLeetCodeFolder(): Promise<string> {
picks.push(
{
label: `Default location`,
detail: `${path.join(os.homedir(), ".leetcode")}`,
value: `${path.join(os.homedir(), ".leetcode")}`,
detail: `${path.join(os.homedir(), ".lcpr")}`,
value: `${path.join(os.homedir(), ".lcpr")}`,
},
{
label: "$(file-directory) Browse...",
Expand All @@ -306,11 +319,61 @@ export async function determineLeetCodeFolder(): Promise<string> {
result = choice.value;
}

getVsCodeConfig().update("workspaceFolder", result, ConfigurationTarget.Global);
await getVsCodeConfig().update("workspaceFolder", result, ConfigurationTarget.Global);

return result;
}

export async function updateWorkSpaceByList(list: Array<string>): Promise<string> {
let result: string;
const picks: Array<IQuickItemEx<string>> = [];

for (let index = 0; index < list.length; index++) {
const element = list[index];
picks.push({
label: `切换workspaceFolder目录为:${element}`,
detail: `${element}`,
value: `${element}`,
});
}

let choice: IQuickItemEx<string> | undefined;

if (picks.length == 1) {
choice = picks[0];
} else {
picks.push({
label: "$(file-directory) Browse...",
value: ":browse",
});

choice = await window.showQuickPick(picks, {
placeHolder: "选择 workspaceFolderList 中的目录作为 workspaceFolder",
});
}

if (!choice) {
result = "";
} else if (choice.value === ":browse") {
const directory: Uri[] | undefined = await showDirectorySelectDialog();
if (!directory || directory.length < 1) {
result = "";
} else {
result = directory[0].fsPath;
}
} else {
result = choice.value;
}

await getVsCodeConfig().update("workspaceFolder", result, ConfigurationTarget.Global);

let workspaceFolderSetting: string = getWorkspaceFolder();
if (workspaceFolderSetting) {
ShowMessage(`原workspaceFolder目录不存在切换为${workspaceFolderSetting}`, OutPutType.info);
}
return result;
}

export function getBelongingWorkspaceFolderUri(fsPath: string | undefined): Uri | undefined {
let defaultUri: Uri | undefined;
if (fsPath) {
Expand Down Expand Up @@ -342,6 +405,29 @@ export function isSubFolder(from: string, to: string): boolean {
return !relative.startsWith("..") && !path.isAbsolute(relative);
}

export async function selectWorkspaceFolderList() {
let workSpaceList = getWorkspaceFolderList();
if (workSpaceList.length > 0) {
// 检查已存在的目录
let checkResult: Array<string> = [];

for (let index = 0; index < workSpaceList.length; index++) {
const checkPath = workSpaceList[index];
let exists = await fse.pathExists(checkPath);
if (exists) {
checkResult.push(checkPath);
}
}

let curWorkSpace = getWorkspaceFolder();
let cur_exists = await fse.pathExists(curWorkSpace);
// 当前目录不存在,且checkResult 可以选择
if (!cur_exists && checkResult.length > 0) {
await updateWorkSpaceByList(checkResult);
}
}
}

export async function selectWorkspaceFolder(isAsk: boolean = true): Promise<string> {
let workspaceFolderSetting: string = getWorkspaceFolder();
if (workspaceFolderSetting.trim() === "") {
Expand Down