From d09581c0e280f0c9f777f9476243db624db50134 Mon Sep 17 00:00:00 2001 From: Abhishek Kathuria Date: Thu, 19 Aug 2021 18:55:16 -0700 Subject: [PATCH 1/5] Add difficulty badge to problems in explorer tree --- package-lock.json | 6 ++-- package.json | 33 +++++++++++++++++-- src/explorer/LeetCodeNode.ts | 11 ++++++- src/explorer/LeetCodeTreeDataProvider.ts | 1 + .../LeetCodeTreeItemDecorationProvider.ts | 31 +++++++++++++++++ src/extension.ts | 2 ++ 6 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/explorer/LeetCodeTreeItemDecorationProvider.ts diff --git a/package-lock.json b/package-lock.json index 75694f3b..4f4cba51 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.59.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.59.0.tgz", + "integrity": "sha512-Zg38rusx2nU6gy6QdF7v4iqgxNfxzlBlDhrRCjOiPQp+sfaNrp3f9J6OHIhpGNN1oOAca4+9Hq0+8u3jwzPMlQ==", "dev": true }, "abab": { diff --git a/package.json b/package.json index cad81253..8b9bc7e0 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "MIT", "icon": "resources/LeetCode.png", "engines": { - "vscode": "^1.50.0" + "vscode": "^1.56.0" }, "repository": { "type": "git", @@ -674,6 +674,35 @@ } } } + ], + "colors": [ + { + "id": "problems.difficulty.badge.easy", + "description": "Color for easy problems badge", + "defaults": { + "light": "#00b8a3", + "dark": "#00b8a3", + "highContrast": "#00b8a3" + } + }, + { + "id": "problems.difficulty.badge.medium", + "description": "Color for medium level problems badge", + "defaults": { + "light": "#ffc01e", + "dark": "#ffc01e", + "highContrast": "#ffc01e" + } + }, + { + "id": "problems.difficulty.badge.hard", + "description": "Color for hard problems badge", + "defaults": { + "light": "#ff375f", + "dark": "#ff375f", + "highContrast": "#ff375f" + } + } ] }, "scripts": { @@ -689,7 +718,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.56.0", "tslint": "^5.20.1", "typescript": "^4.3.2" }, diff --git a/src/explorer/LeetCodeNode.ts b/src/explorer/LeetCodeNode.ts index 67aad324..c8540887 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 2bfbe497..4764934a 100644 --- a/src/explorer/LeetCodeTreeDataProvider.ts +++ b/src/explorer/LeetCodeTreeDataProvider.ts @@ -51,6 +51,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider { + 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], + }; + } +} + +export const leetCodeTreeItemDecorationProvider: LeetCodeTreeItemDecorationProvider = new LeetCodeTreeItemDecorationProvider(); diff --git a/src/extension.ts b/src/extension.ts index 5bd026f1..102c245f 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()), From 3864dbf7c93ee258edba15177db0e4a6ffa6d54d Mon Sep 17 00:00:00 2001 From: Abhishek Kathuria Date: Thu, 19 Aug 2021 19:20:08 -0700 Subject: [PATCH 2/5] Remove custom colors and rely on inbuilt colors for better theme support --- package.json | 29 ------------------- .../LeetCodeTreeItemDecorationProvider.ts | 6 ++-- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 8b9bc7e0..200c40b1 100644 --- a/package.json +++ b/package.json @@ -674,35 +674,6 @@ } } } - ], - "colors": [ - { - "id": "problems.difficulty.badge.easy", - "description": "Color for easy problems badge", - "defaults": { - "light": "#00b8a3", - "dark": "#00b8a3", - "highContrast": "#00b8a3" - } - }, - { - "id": "problems.difficulty.badge.medium", - "description": "Color for medium level problems badge", - "defaults": { - "light": "#ffc01e", - "dark": "#ffc01e", - "highContrast": "#ffc01e" - } - }, - { - "id": "problems.difficulty.badge.hard", - "description": "Color for hard problems badge", - "defaults": { - "light": "#ff375f", - "dark": "#ff375f", - "highContrast": "#ff375f" - } - } ] }, "scripts": { diff --git a/src/explorer/LeetCodeTreeItemDecorationProvider.ts b/src/explorer/LeetCodeTreeItemDecorationProvider.ts index 3c755f50..ac7ff00d 100644 --- a/src/explorer/LeetCodeTreeItemDecorationProvider.ts +++ b/src/explorer/LeetCodeTreeItemDecorationProvider.ts @@ -9,9 +9,9 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide }; private readonly ITEM_COLOR: { [key: string]: ThemeColor } = { - easy: new ThemeColor("problems.difficulty.badge.easy"), - medium: new ThemeColor("problems.difficulty.badge.medium"), - hard: new ThemeColor("problems.difficulty.badge.hard"), + easy: new ThemeColor("charts.green"), + medium: new ThemeColor("charts.yellow"), + hard: new ThemeColor("charts.red"), }; public provideFileDecoration(uri: Uri): ProviderResult { From 96177cafefd0e079379cf7c4cf537b172e86a548 Mon Sep 17 00:00:00 2001 From: Abhishek Kathuria Date: Thu, 19 Aug 2021 19:46:44 -0700 Subject: [PATCH 3/5] Add support to enable/disable difficulty badge and colorization --- package.json | 8 +++++++- src/explorer/LeetCodeTreeItemDecorationProvider.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 200c40b1..763f22a5 100644 --- a/package.json +++ b/package.json @@ -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": false, + "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.56.0", + "@types/vscode": "1.56.0", "tslint": "^5.20.1", "typescript": "^4.3.2" }, diff --git a/src/explorer/LeetCodeTreeItemDecorationProvider.ts b/src/explorer/LeetCodeTreeItemDecorationProvider.ts index ac7ff00d..103ce2d9 100644 --- a/src/explorer/LeetCodeTreeItemDecorationProvider.ts +++ b/src/explorer/LeetCodeTreeItemDecorationProvider.ts @@ -1,5 +1,5 @@ import { URLSearchParams } from "url"; -import { FileDecoration, FileDecorationProvider, ProviderResult, ThemeColor, Uri } from "vscode"; +import { FileDecoration, FileDecorationProvider, ProviderResult, ThemeColor, Uri, workspace, WorkspaceConfiguration } from "vscode"; export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvider { private readonly DIFFICULTY_BADGE_LABEL: { [key: string]: string } = { @@ -15,6 +15,10 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide }; public provideFileDecoration(uri: Uri): ProviderResult { + if (!this.isDifficultyBadgeEnabled()) { + return; + } + if (uri.scheme !== "leetcode" && uri.authority !== "problems") { return; } @@ -26,6 +30,11 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide 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(); From 27602f824d39ab707124b66929abda59bc4b5433 Mon Sep 17 00:00:00 2001 From: Abhishek Kathuria Date: Thu, 19 Aug 2021 20:03:21 -0700 Subject: [PATCH 4/5] Enable colorize problems by default, Update README with colorizeProblems flag --- README.md | 32 +++++++++++++++++--------------- package.json | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 249e20bd..8292a79f 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.json b/package.json index 763f22a5..e94690cd 100644 --- a/package.json +++ b/package.json @@ -674,7 +674,7 @@ }, "leetcode.colorizeProblems": { "type": "boolean", - "default": false, + "default": true, "scope": "application", "description": "Add difficulty badge and colorize problems files in explorer tree." } From 12410edc1a7e7e92828392fd11bad3d29fbf222d Mon Sep 17 00:00:00 2001 From: Abhishek Kathuria Date: Thu, 19 Aug 2021 20:20:45 -0700 Subject: [PATCH 5/5] Bump vscode engine to 1.57.0 --- package-lock.json | 6 +++--- package.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4f4cba51..4ab065af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,9 +79,9 @@ "dev": true }, "@types/vscode": { - "version": "1.59.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.59.0.tgz", - "integrity": "sha512-Zg38rusx2nU6gy6QdF7v4iqgxNfxzlBlDhrRCjOiPQp+sfaNrp3f9J6OHIhpGNN1oOAca4+9Hq0+8u3jwzPMlQ==", + "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 e94690cd..7ecd780a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "MIT", "icon": "resources/LeetCode.png", "engines": { - "vscode": "^1.56.0" + "vscode": "^1.57.0" }, "repository": { "type": "git", @@ -695,7 +695,7 @@ "@types/mocha": "^2.2.42", "@types/node": "^14.14.33", "@types/require-from-string": "^1.2.0", - "@types/vscode": "1.56.0", + "@types/vscode": "1.57.0", "tslint": "^5.20.1", "typescript": "^4.3.2" },