From 97b5684dc31aec300caa621814f9a101d33e5a1c Mon Sep 17 00:00:00 2001 From: Darren Sadr Date: Sun, 6 Mar 2022 21:02:11 -0600 Subject: [PATCH 1/3] Added options to configure showing companies, tags and metadata in problem preview --- package.json | 18 ++++++++++++++++++ src/utils/settingUtils.ts | 12 ++++++++++++ src/webview/leetCodePreviewProvider.ts | 12 ++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bcdb5c0..79c65fc 100644 --- a/package.json +++ b/package.json @@ -700,6 +700,24 @@ "Acceptance Rate (Descending)" ], "description": "Sorting strategy for problems list." + }, + "leetcode.preview.showCompanies": { + "type": "boolean", + "default": true, + "scope": "application", + "description": "Show list of companies in problem preview." + }, + "leetcode.preview.showTags": { + "type": "boolean", + "default": true, + "scope": "application", + "description": "Show list of tags in problem preview." + }, + "leetcode.preview.showMetadata": { + "type": "boolean", + "default": true, + "scope": "application", + "description": "Show problem metadata (category, difficulty, likes, dislikes) in problem preview." } } } diff --git a/src/utils/settingUtils.ts b/src/utils/settingUtils.ts index 7b6eb6c..569857c 100644 --- a/src/utils/settingUtils.ts +++ b/src/utils/settingUtils.ts @@ -29,6 +29,18 @@ export function shouldUseEndpointTranslation(): boolean { return getWorkspaceConfiguration().get("useEndpointTranslation", true); } +export function shouldShowCompaniesInProblemPreview(): boolean { + return getWorkspaceConfiguration().get("preview.showCompanies", true); +} + +export function shouldShowTagsInProblemPreview(): boolean { + return getWorkspaceConfiguration().get("preview.showTags", true); +} + +export function shouldShowMetadataInProblemPreview(): boolean { + return getWorkspaceConfiguration().get("preview.showMetadata", true); +} + export function getDescriptionConfiguration(): IDescriptionConfiguration { const setting: string = getWorkspaceConfiguration().get("showDescription", DescriptionConfiguration.InWebView); const config: IDescriptionConfiguration = { diff --git a/src/webview/leetCodePreviewProvider.ts b/src/webview/leetCodePreviewProvider.ts index 78b4099..e0985c9 100644 --- a/src/webview/leetCodePreviewProvider.ts +++ b/src/webview/leetCodePreviewProvider.ts @@ -6,6 +6,7 @@ import { getLeetCodeEndpoint } from "../commands/plugin"; import { Endpoint, IProblem } from "../shared"; import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview"; import { markdownEngine } from "./markdownEngine"; +import * as settingUtils from "../utils/settingUtils"; class LeetCodePreviewProvider extends LeetCodeWebview { @@ -13,6 +14,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview { private node: IProblem; private description: IDescription; private sideMode: boolean = false; + private shouldShowCompanies = settingUtils.shouldShowCompaniesInProblemPreview(); + private shouldShowTags = settingUtils.shouldShowTagsInProblemPreview(); + private shouldShowMetadata = settingUtils.shouldShowMetadataInProblemPreview(); public isSideMode(): boolean { return this.sideMode; @@ -73,7 +77,7 @@ class LeetCodePreviewProvider extends LeetCodeWebview { }; const { title, url, category, difficulty, likes, dislikes, body } = this.description; const head: string = markdownEngine.render(`# [${title}](${url})`); - const info: string = markdownEngine.render([ + const metadata: string = markdownEngine.render([ `| Category | Difficulty | Likes | Dislikes |`, `| :------: | :--------: | :---: | :------: |`, `| ${category} | ${difficulty} | ${likes} | ${dislikes} |`, @@ -112,9 +116,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview { ${head} - ${info} - ${tags} - ${companies} + ${this.shouldShowMetadata ? metadata : ""} + ${this.shouldShowTags ? tags : ""} + ${this.shouldShowCompanies ? companies : ""} ${body}
${links} From ad06495308cdce16598a8c574ae30c8428ef0a7e Mon Sep 17 00:00:00 2001 From: Darren Sadr Date: Mon, 7 Mar 2022 17:20:17 -0600 Subject: [PATCH 2/3] Adds problem id to the preview headline --- src/webview/leetCodePreviewProvider.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webview/leetCodePreviewProvider.ts b/src/webview/leetCodePreviewProvider.ts index e0985c9..036ec51 100644 --- a/src/webview/leetCodePreviewProvider.ts +++ b/src/webview/leetCodePreviewProvider.ts @@ -76,7 +76,8 @@ class LeetCodePreviewProvider extends LeetCodeWebview { `, }; const { title, url, category, difficulty, likes, dislikes, body } = this.description; - const head: string = markdownEngine.render(`# [${title}](${url})`); + const id = this.node.id; + const head: string = markdownEngine.render(`# [${id}. ${title}](${url})`); const metadata: string = markdownEngine.render([ `| Category | Difficulty | Likes | Dislikes |`, `| :------: | :--------: | :---: | :------: |`, From 325cadce6142b9a81a65abadcafb10c602d00068 Mon Sep 17 00:00:00 2001 From: Darren Sadr Date: Mon, 14 Mar 2022 03:34:24 -0500 Subject: [PATCH 3/3] Fixes #1 and #4 --- README.md | 35 ++++++++++--------- package.json | 10 ++++-- src/codelens/CustomCodeLensProvider.ts | 2 +- .../LeetCodeTreeItemDecorationProvider.ts | 26 +++++++++----- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ac752c7..befce61 100644 --- a/README.md +++ b/README.md @@ -120,23 +120,24 @@ 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` | -| `leetcode.colorizeProblems` | Add difficulty badge and colorize problems files in explorer tree | `true` | -| `leetcode.problems.sortStrategy` | Specify sorting strategy for problems list | `None` | +| 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.explorerTree.colorize` | Colorize problems in explorer tree based on difficulty. | `true` | +| `leetcode.explorerTree.showDifficultyBadge` | Add difficulty badge next to problems in explorer tree. | `true` | +| `leetcode.problems.sortStrategy` | Specify sorting strategy for problems list | `None` | ## Want Help? diff --git a/package.json b/package.json index 79c65fc..5e12adc 100644 --- a/package.json +++ b/package.json @@ -684,11 +684,17 @@ "scope": "application", "description": "The Node.js executable path. for example, C:\\Program Files\\nodejs\\node.exe" }, - "leetcode.colorizeProblems": { + "leetcode.explorerTree.colorize": { "type": "boolean", "default": true, "scope": "application", - "description": "Add difficulty badge and colorize problems files in explorer tree." + "description": "Colorize problems based on difficulty." + }, + "leetcode.explorerTree.showDifficultyBadge": { + "type": "boolean", + "default": true, + "scope": "application", + "description": "Show difficulty badge next to problem name." }, "leetcode.problems.sortStrategy": { "type": "string", diff --git a/src/codelens/CustomCodeLensProvider.ts b/src/codelens/CustomCodeLensProvider.ts index 4b9b649..2fab60c 100644 --- a/src/codelens/CustomCodeLensProvider.ts +++ b/src/codelens/CustomCodeLensProvider.ts @@ -38,7 +38,7 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider { let codeLensLine: number = document.lineCount - 1; for (let i: number = document.lineCount - 1; i >= 0; i--) { const lineContent: string = document.lineAt(i).text; - if (lineContent.indexOf("@lc code=end") >= 0) { + if (lineContent.indexOf("@lc code=end") == 0) { codeLensLine = i; break; } diff --git a/src/explorer/LeetCodeTreeItemDecorationProvider.ts b/src/explorer/LeetCodeTreeItemDecorationProvider.ts index 103ce2d..851df12 100644 --- a/src/explorer/LeetCodeTreeItemDecorationProvider.ts +++ b/src/explorer/LeetCodeTreeItemDecorationProvider.ts @@ -14,10 +14,7 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide hard: new ThemeColor("charts.red"), }; - public provideFileDecoration(uri: Uri): ProviderResult { - if (!this.isDifficultyBadgeEnabled()) { - return; - } + public provideFileDecoration(uri: Uri): ProviderResult { if (uri.scheme !== "leetcode" && uri.authority !== "problems") { return; @@ -25,15 +22,26 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide 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], - }; + + var decoration = {} + if (this.isDifficultyColorizationEnabled()) { + decoration["color"] = this.ITEM_COLOR[difficulty] + } + if (this.isDifficultyBadgeEnabled()) { + decoration["badge"] = this.DIFFICULTY_BADGE_LABEL[difficulty] + } + + return decoration; + } + + private isDifficultyColorizationEnabled(): boolean { + const configuration: WorkspaceConfiguration = workspace.getConfiguration(); + return configuration.get("leetcode.explorerTree.colorize", false); } private isDifficultyBadgeEnabled(): boolean { const configuration: WorkspaceConfiguration = workspace.getConfiguration(); - return configuration.get("leetcode.colorizeProblems", false); + return configuration.get("leetcode.explorerTree.showDifficultyBadge", false); } }