diff --git a/CHANGELOG.md b/CHANGELOG.md index ba24c4b..f8df44e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# version 3.1.10 + +- 没有分数的题目 按照 简单->绿色、中等->黄色、困难->红色 上色 +- 增加配置 workspaceFolderList 当 workspaceFolder 所在目录不存在,尝试从 workspaceFolderList 获取可用目录 + # version 3.1.9 - 在 Windows 上的 Python3 调试,当用例是字符串 " " 且包含空格,会使得调试参数解析错误 diff --git a/README.md b/README.md index 78d2f01..999c309 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,8 @@ | leetcode-problem-rating.defaultLanguage | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`, `swift`, `typescript` | `N/A` | | leetcode-problem-rating.useWsl | 指定是否启用 WSL | `false` | | leetcode-problem-rating.endpoint | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | leetcode.cn | -| leetcode-problem-rating.workspaceFolder | 指定保存文件的工作区目例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值, 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode 录 | `""` | +| leetcode-problem-rating.workspaceFolder | 指定保存文件的工作区目录例如/home/${USERNAME}/leetcode, 现在会尝试从系统环境变量读取 USERNAME 对应的值, 例如环境变量中 USERNAME 是 ccagml,那么就会是/home/ccagml/leetcode 录 | `""` | +| leetcode-problem-rating.workspaceFolderList | 多个等待选择的工作区目录,如果 workspaceFolder 目录不存在,尝试从 workspaceFolderList 选取可用目录 | `["path1", "path2"]` | | leetcode-problem-rating.filePath | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](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}题目的中文名称 | | | leetcode-problem-rating.enableStatusBar | 指定是否在 VS Code 下方显示插件状态栏。 增加周赛分数据 | `true` | | leetcode-problem-rating.editor.shortcuts | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `star`, `solution`, `description`, case, allcase 。 | ["submit, case, allcase, test, solution"] | diff --git a/package.json b/package.json index ac253f0..f5307ae 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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%", diff --git a/package.nls.json b/package.nls.json index 0d5525a..4c1be8d 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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.", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index 72b4ff0..d55f444 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -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": "是否显示计时器。", diff --git a/src/BABA.ts b/src/BABA.ts index 1235d2c..61898a0 100644 --- a/src/BABA.ts +++ b/src/BABA.ts @@ -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", diff --git a/src/extension.ts b/src/extension.ts index cae78fd..db9d792 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -218,6 +218,7 @@ export async function activate(context: ExtensionContext): Promise { ) ); + await BABA.sendNotificationAsync(BabaStr.InitWorkspaceFolder, context); await BABA.sendNotificationAsync(BabaStr.InitFile, context); await BABA.sendNotificationAsync(BabaStr.InitEnv, context); await BABA.sendNotificationAsync(BabaStr.InitLoginStatus); diff --git a/src/treeColor/TreeColorModule.ts b/src/treeColor/TreeColorModule.ts index 167da37..27a1d37 100644 --- a/src/treeColor/TreeColorModule.ts +++ b/src/treeColor/TreeColorModule.ts @@ -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; } diff --git a/src/treeData/TreeDataService.ts b/src/treeData/TreeDataService.ts index a05331d..48033c7 100644 --- a/src/treeData/TreeDataService.ts +++ b/src/treeData/TreeDataService.ts @@ -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 { @@ -45,6 +50,10 @@ export class TreeDataService implements vscode.TreeDataProvider { await treeViewController.refreshCheck(); } + public async checkWorkspaceFolder() { + await selectWorkspaceFolderList(); + } + public getTreeItem(element: TreeNodeModel): vscode.TreeItem | Thenable { if (element.id === "notSignIn") { return { @@ -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) { @@ -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: diff --git a/src/utils/ConfigUtils.ts b/src/utils/ConfigUtils.ts index be442da..fd865ab 100644 --- a/src/utils/ConfigUtils.ts +++ b/src/utils/ConfigUtils.ts @@ -28,6 +28,7 @@ import { OpenOption, IQuickItemEx, singleLineFlag, + OutPutType, } from "../model/ConstDefind"; import { useWsl, toWslPath } from "../utils/SystemUtils"; @@ -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 { @@ -94,6 +96,17 @@ export function getWorkspaceFolder(): string { return resolveWorkspaceFolder(cur_wsf); } +// 工作目录 +export function getWorkspaceFolderList(): Array { + let cur_wsf = getVsCodeConfig().get>("workspaceFolderList", []); + let result: Array = []; + 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[]) => { @@ -282,8 +295,8 @@ export async function determineLeetCodeFolder(): Promise { 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...", @@ -306,11 +319,61 @@ export async function determineLeetCodeFolder(): Promise { result = choice.value; } - getVsCodeConfig().update("workspaceFolder", result, ConfigurationTarget.Global); + await getVsCodeConfig().update("workspaceFolder", result, ConfigurationTarget.Global); return result; } +export async function updateWorkSpaceByList(list: Array): Promise { + let result: string; + const picks: Array> = []; + + for (let index = 0; index < list.length; index++) { + const element = list[index]; + picks.push({ + label: `切换workspaceFolder目录为:${element}`, + detail: `${element}`, + value: `${element}`, + }); + } + + let choice: IQuickItemEx | 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) { @@ -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 = []; + + 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 { let workspaceFolderSetting: string = getWorkspaceFolder(); if (workspaceFolderSetting.trim() === "") {