diff --git a/README.md b/README.md index 249e20b..8292a79 100644 --- a/README.md +++ b/README.md @@ -119,21 +119,23 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh ## Settings -| Setting Name | Description | Default Value | -| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -| `leetcode.hideSolved` | Specify to hide the solved problems or not | `false` | -| `leetcode.showLocked` | Specify to show the locked problems or not. Only Premium users could open the locked problems | `false` | -| `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`, `typescript` | `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.workspaceFolder` | Specify the path of the workspace folder to store the problem files. | `""` | -| `leetcode.filePath` | Specify the relative path under the workspace and the file name to save the problem files. More details can be found [here](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/Customize-the-Relative-Folder-and-the-File-Name-of-the-Problem-File). | | -| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` | -| `leetcode.editor.shortcuts` | Specify the customized shortcuts in editors. Supported values are: `submit`, `test`, `star`, `solution` and `description`. | `["submit, test"]` | -| `leetcode.enableSideMode` | Specify whether `preview`, `solution` and `submission` tab should be grouped into the second editor column when solving a problem. | `true` | -| `leetcode.nodePath` | Specify the `Node.js` executable path. for example, C:\Program Files\nodejs\node.exe | `node` | -| `leetcode.showCommentDescription` | Specify whether to include the problem description in the comments | `false` | -| `leetcode.useEndpointTranslation` | Use endpoint's translation (if available) | `true` | + +| Setting Name | Description | Default Value | +| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | +| `leetcode.hideSolved` | Specify to hide the solved problems or not | `false` | +| `leetcode.showLocked` | Specify to show the locked problems or not. Only Premium users could open the locked problems | `false` | +| `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`, `typescript` | `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.workspaceFolder` | Specify the path of the workspace folder to store the problem files. | `""` | +| `leetcode.filePath` | Specify the relative path under the workspace and the file name to save the problem files. More details can be found [here](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/Customize-the-Relative-Folder-and-the-File-Name-of-the-Problem-File). | | +| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` | +| `leetcode.editor.shortcuts` | Specify the customized shortcuts in editors. Supported values are: `submit`, `test`, `star`, `solution` and `description`. | `["submit, test"]` | +| `leetcode.enableSideMode` | Specify whether `preview`, `solution` and `submission` tab should be grouped into the second editor column when solving a problem. | `true` | +| `leetcode.nodePath` | Specify the `Node.js` executable path. for example, C:\Program Files\nodejs\node.exe | `node` | +| `leetcode.showCommentDescription` | Specify whether to include the problem description in the comments | `false` | +| `leetcode.useEndpointTranslation` | Use endpoint's translation (if available) | `true` | +| `leetcode.colorizeProblems` | Add difficulty badge and colorize problems files in explorer tree | `true` | ## Want Help? diff --git a/package-lock.json b/package-lock.json index 75694f3..4ab065a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,9 +79,9 @@ "dev": true }, "@types/vscode": { - "version": "1.50.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.50.0.tgz", - "integrity": "sha512-QnIeyi4L2DiD9M2bAQKRzT/EQvc80qP9UL6JD5TiLlNRL1khIDg4ej4mDSRbtFrDAsRntFI1RhMvdomUThMsqg==", + "version": "1.57.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.57.0.tgz", + "integrity": "sha512-FeznBFtIDCWRluojTsi9c3LLcCHOXP5etQfBK42+ixo1CoEAchkw39tuui9zomjZuKfUVL33KZUDIwHZ/xvOkQ==", "dev": true }, "abab": { diff --git a/package.json b/package.json index cad8125..7ecd780 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "MIT", "icon": "resources/LeetCode.png", "engines": { - "vscode": "^1.50.0" + "vscode": "^1.57.0" }, "repository": { "type": "git", @@ -671,6 +671,12 @@ "default": "node", "scope": "application", "description": "The Node.js executable path. for example, C:\\Program Files\\nodejs\\node.exe" + }, + "leetcode.colorizeProblems": { + "type": "boolean", + "default": true, + "scope": "application", + "description": "Add difficulty badge and colorize problems files in explorer tree." } } } @@ -689,7 +695,7 @@ "@types/mocha": "^2.2.42", "@types/node": "^14.14.33", "@types/require-from-string": "^1.2.0", - "@types/vscode": "1.50.0", + "@types/vscode": "1.57.0", "tslint": "^5.20.1", "typescript": "^4.3.2" }, diff --git a/src/explorer/LeetCodeNode.ts b/src/explorer/LeetCodeNode.ts index 67aad32..c854088 100644 --- a/src/explorer/LeetCodeNode.ts +++ b/src/explorer/LeetCodeNode.ts @@ -1,7 +1,7 @@ // Copyright (c) jdneo. All rights reserved. // Licensed under the MIT license. -import { Command } from "vscode"; +import { Command, Uri } from "vscode"; import { IProblem, ProblemState } from "../shared"; export class LeetCodeNode { @@ -55,4 +55,13 @@ export class LeetCodeNode { }; } + public get uri(): Uri { + return Uri.from({ + scheme: "leetcode", + authority: this.isProblem ? "problems" : "tree-node", + path: `/${this.id}`, // path must begin with slash / + query: `difficulty=${this.difficulty}`, + }); + } + } diff --git a/src/explorer/LeetCodeTreeDataProvider.ts b/src/explorer/LeetCodeTreeDataProvider.ts index 2bfbe49..4764934 100644 --- a/src/explorer/LeetCodeTreeDataProvider.ts +++ b/src/explorer/LeetCodeTreeDataProvider.ts @@ -51,6 +51,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider { + if (!this.isDifficultyBadgeEnabled()) { + return; + } + + if (uri.scheme !== "leetcode" && uri.authority !== "problems") { + return; + } + + const params: URLSearchParams = new URLSearchParams(uri.query); + const difficulty: string = params.get("difficulty")!.toLowerCase(); + return { + badge: this.DIFFICULTY_BADGE_LABEL[difficulty], + color: this.ITEM_COLOR[difficulty], + }; + } + + private isDifficultyBadgeEnabled(): boolean { + const configuration: WorkspaceConfiguration = workspace.getConfiguration(); + return configuration.get("leetcode.colorizeProblems", false); + } +} + +export const leetCodeTreeItemDecorationProvider: LeetCodeTreeItemDecorationProvider = new LeetCodeTreeItemDecorationProvider(); diff --git a/src/extension.ts b/src/extension.ts index 5bd026f..102c245 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,6 +14,7 @@ import * as test from "./commands/test"; import { explorerNodeManager } from "./explorer/explorerNodeManager"; import { LeetCodeNode } from "./explorer/LeetCodeNode"; import { leetCodeTreeDataProvider } from "./explorer/LeetCodeTreeDataProvider"; +import { leetCodeTreeItemDecorationProvider } from "./explorer/LeetCodeTreeItemDecorationProvider"; import { leetCodeChannel } from "./leetCodeChannel"; import { leetCodeExecutor } from "./leetCodeExecutor"; import { leetCodeManager } from "./leetCodeManager"; @@ -47,6 +48,7 @@ export async function activate(context: vscode.ExtensionContext): Promise markdownEngine, codeLensController, explorerNodeManager, + vscode.window.registerFileDecorationProvider(leetCodeTreeItemDecorationProvider), vscode.window.createTreeView("leetCodeExplorer", { treeDataProvider: leetCodeTreeDataProvider, showCollapseAll: true }), vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()), vscode.commands.registerCommand("leetcode.toggleLeetCodeCn", () => plugin.switchEndpoint()),