- Notifications
You must be signed in to change notification settings - Fork670
Add difficulty badge to problems in explorer tree#727
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
d09581c
Add difficulty badge to problems in explorer tree
anshkathuria3864dbf
Remove custom colors and rely on inbuilt colors for better theme support
anshkathuria96177ca
Add support to enable/disable difficulty badge and colorization
anshkathuria27602f8
Enable colorize problems by default, Update README with colorizeProbl…
anshkathuria12410ed
Bump vscode engine to 1.57.0
anshkathuriaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
32 changes: 17 additions & 15 deletionsREADME.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletionspackage-lock.json
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
10 changes: 8 additions & 2 deletionspackage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletionsrc/explorer/LeetCodeNode.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright (c) jdneo. All rights reserved. | ||
// Licensed under the MIT license. | ||
import{Command,Uri}from"vscode"; | ||
import{IProblem,ProblemState}from"../shared"; | ||
exportclassLeetCodeNode{ | ||
@@ -55,4 +55,13 @@ export class LeetCodeNode { | ||
}; | ||
} | ||
publicgeturi():Uri{ | ||
returnUri.from({ | ||
anshkathuria marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
scheme:"leetcode", | ||
authority:this.isProblem ?"problems" :"tree-node", | ||
path:`/${this.id}`,// path must begin with slash / | ||
query:`difficulty=${this.difficulty}`, | ||
}); | ||
} | ||
} |
1 change: 1 addition & 0 deletionssrc/explorer/LeetCodeTreeDataProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletionssrc/explorer/LeetCodeTreeItemDecorationProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { URLSearchParams } from "url"; | ||
import { FileDecoration, FileDecorationProvider, ProviderResult, ThemeColor, Uri, workspace, WorkspaceConfiguration } from "vscode"; | ||
export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvider { | ||
private readonly DIFFICULTY_BADGE_LABEL: { [key: string]: string } = { | ||
easy: "E", | ||
medium: "M", | ||
hard: "H", | ||
}; | ||
private readonly ITEM_COLOR: { [key: string]: ThemeColor } = { | ||
easy: new ThemeColor("charts.green"), | ||
medium: new ThemeColor("charts.yellow"), | ||
hard: new ThemeColor("charts.red"), | ||
}; | ||
public provideFileDecoration(uri: Uri): ProviderResult<FileDecoration> { | ||
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<boolean>("leetcode.colorizeProblems", false); | ||
} | ||
} | ||
export const leetCodeTreeItemDecorationProvider: LeetCodeTreeItemDecorationProvider = new LeetCodeTreeItemDecorationProvider(); |
2 changes: 2 additions & 0 deletionssrc/extension.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.