Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to configure showing companies, tags and metadata in problem preview #778

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
28 changes: 26 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -700,6 +706,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."
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/codelens/CustomCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
26 changes: 17 additions & 9 deletions src/explorer/LeetCodeTreeItemDecorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,34 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide
hard: new ThemeColor("charts.red"),
};

public provideFileDecoration(uri: Uri): ProviderResult<FileDecoration> {
if (!this.isDifficultyBadgeEnabled()) {
return;
}
public provideFileDecoration(uri: Uri): ProviderResult<FileDecoration> {

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],
};

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<boolean>("leetcode.explorerTree.colorize", false);
}

private isDifficultyBadgeEnabled(): boolean {
const configuration: WorkspaceConfiguration = workspace.getConfiguration();
return configuration.get<boolean>("leetcode.colorizeProblems", false);
return configuration.get<boolean>("leetcode.explorerTree.showDifficultyBadge", false);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/utils/settingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ export function shouldUseEndpointTranslation(): boolean {
return getWorkspaceConfiguration().get<boolean>("useEndpointTranslation", true);
}

export function shouldShowCompaniesInProblemPreview(): boolean {
return getWorkspaceConfiguration().get<boolean>("preview.showCompanies", true);
}

export function shouldShowTagsInProblemPreview(): boolean {
return getWorkspaceConfiguration().get<boolean>("preview.showTags", true);
}

export function shouldShowMetadataInProblemPreview(): boolean {
return getWorkspaceConfiguration().get<boolean>("preview.showMetadata", true);
}

export function getDescriptionConfiguration(): IDescriptionConfiguration {
const setting: string = getWorkspaceConfiguration().get<string>("showDescription", DescriptionConfiguration.InWebView);
const config: IDescriptionConfiguration = {
Expand Down
15 changes: 10 additions & 5 deletions src/webview/leetCodePreviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ 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 {

protected readonly viewType: string = "leetcode.preview";
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;
Expand Down Expand Up @@ -72,8 +76,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
</style>`,
};
const { title, url, category, difficulty, likes, dislikes, body } = this.description;
const head: string = markdownEngine.render(`# [${title}](${url})`);
const info: string = markdownEngine.render([
const id = this.node.id;
const head: string = markdownEngine.render(`# [${id}. ${title}](${url})`);
const metadata: string = markdownEngine.render([
`| Category | Difficulty | Likes | Dislikes |`,
`| :------: | :--------: | :---: | :------: |`,
`| ${category} | ${difficulty} | ${likes} | ${dislikes} |`,
Expand Down Expand Up @@ -112,9 +117,9 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
</head>
<body>
${head}
${info}
${tags}
${companies}
${this.shouldShowMetadata ? metadata : ""}
${this.shouldShowTags ? tags : ""}
${this.shouldShowCompanies ? companies : ""}
${body}
<hr />
${links}
Expand Down