Skip to content

Add tooltips for sub-category folder #143

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

Merged
merged 4 commits into from
Feb 20, 2019
Merged
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
31 changes: 31 additions & 0 deletions src/explorer/LeetCodeTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
const idPrefix: number = Date.now();
return {
label: element.isProblem ? `[${element.id}] ${element.name}` : element.name,
tooltip: this.getSubCategoryTooltip(element),
id: `${idPrefix}.${element.parentName}.${element.id}`,
collapsibleState: element.isProblem ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed,
contextValue: element.isProblem ? "problem" : element.id.toLowerCase(),
Expand Down Expand Up @@ -168,6 +169,36 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
}
}

private getSubCategoryTooltip(element: LeetCodeNode): string {
// return '' unless it is a sub-category node
if (element.isProblem || !this.treeData[element.parentName]) {
return "";
}

const problems: IProblem[] = this.treeData[element.parentName].get(element.id);

let numAC: number = 0;
let numNotAC: number = 0;
let numUnknown: number = 0;
for (const prob of problems) {
switch (prob.state) {
case ProblemState.AC:
numAC++;
break;
case ProblemState.NotAC:
numNotAC++;
break;
case ProblemState.Unknown:
numUnknown++;
break;
default:
break;
}
}

return `AC: ${numAC}\nNot AC: ${numNotAC}\nUnknown: ${numUnknown}\nTotal: ${problems.length}`;
}

private addProblemToTreeData(problem: IProblem): void {
this.putProblemToMap(this.treeData.Difficulty, problem.difficulty, problem);
for (const tag of problem.tags) {
Expand Down