Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand All @@ -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"
},
Expand Down
11 changes: 10 additions & 1 deletion src/explorer/LeetCodeTreeItemDecorationProvider.ts
Original file line number Diff line number Diff line change
@@ -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 } = {
Expand All @@ -15,6 +15,10 @@ export class LeetCodeTreeItemDecorationProvider implements FileDecorationProvide
};

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

if (uri.scheme !== "leetcode" && uri.authority !== "problems") {
return;
}
Expand All @@ -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<boolean>("leetcode.colorizeProblems", false);
}
}

export const leetCodeTreeItemDecorationProvider: LeetCodeTreeItemDecorationProvider = new LeetCodeTreeItemDecorationProvider();