Skip to content

Commit 331ea70

Browse files
authored
fix the icon bug in explorer (LeetCode-OpenSource#14)
1 parent bc2caa1 commit 331ea70

File tree

5 files changed

+61
-15
lines changed

5 files changed

+61
-15
lines changed

resources/x.png

3.04 KB
Loading

src/commands/list.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import * as vscode from "vscode";
44
import { leetCodeManager } from "../leetCodeManager";
5-
import { leetCodeBinaryPath } from "../shared";
6-
import { UserStatus } from "../shared";
5+
import { leetCodeBinaryPath, ProblemState, UserStatus } from "../shared";
76
import { executeCommand } from "../utils/cpUtils";
87
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
98

109
export interface IProblem {
11-
solved: boolean;
10+
state: ProblemState;
1211
id: string;
1312
name: string;
1413
difficulty: string;
@@ -28,7 +27,7 @@ export async function listProblems(channel: vscode.OutputChannel): Promise<IProb
2827
const match: RegExpMatchArray | null = line.match(reg);
2928
if (match && match.length === 6) {
3029
problems.push({
31-
solved: !!(match[1].trim()),
30+
state: parseProblemState(match[1]),
3231
id: match[2].trim(),
3332
name: match[3].trim(),
3433
difficulty: match[4].trim(),
@@ -41,5 +40,22 @@ export async function listProblems(channel: vscode.OutputChannel): Promise<IProb
4140
await promptForOpenOutputChannel("Failed to list problems. Please open the output channel for details", DialogType.error, channel);
4241
return [];
4342
}
43+
}
4444

45+
function parseProblemState(stateOutput: string): ProblemState {
46+
if (!stateOutput) {
47+
return ProblemState.Unknown;
48+
}
49+
switch (stateOutput.trim()) {
50+
case "v":
51+
case "✔":
52+
case "√":
53+
return ProblemState.AC;
54+
case "X":
55+
case "✘":
56+
case "×":
57+
return ProblemState.NotAC;
58+
default:
59+
return ProblemState.Unknown;
60+
}
4561
}

src/commands/show.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as fse from "fs-extra";
44
import * as vscode from "vscode";
55
import { LeetCodeNode } from "../leetCodeExplorer";
66
import { leetCodeManager } from "../leetCodeManager";
7-
import { IQuickItemEx, languages, leetCodeBinaryPath } from "../shared";
7+
import { IQuickItemEx, languages, leetCodeBinaryPath, ProblemState } from "../shared";
88
import { executeCommand } from "../utils/cpUtils";
99
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
1010
import { selectWorkspaceFolder } from "../utils/workspaceUtils";
@@ -79,11 +79,22 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
7979
async function parseProblemsToPicks(p: Promise<list.IProblem[]>): Promise<Array<IQuickItemEx<string>>> {
8080
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
8181
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: list.IProblem) => Object.assign({}, {
82-
label: `${problem.solved ? "$(check) " : ""}${problem.id}.${problem.name}`,
82+
label: `${parseProblemDecorator(problem.state)}${problem.id}.${problem.name}`,
8383
description: "",
8484
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
8585
value: problem.id,
8686
}));
8787
resolve(picks);
8888
});
8989
}
90+
91+
function parseProblemDecorator(state: ProblemState): string {
92+
switch (state) {
93+
case ProblemState.AC:
94+
return "$(check) ";
95+
case ProblemState.NotAC:
96+
return "$(x) ";
97+
default:
98+
return "";
99+
}
100+
}

src/leetCodeExplorer.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import * as vscode from "vscode";
55
import * as list from "./commands/list";
66
import { leetCodeManager } from "./leetCodeManager";
7+
import { ProblemState } from "./shared";
78

89
// tslint:disable:max-classes-per-file
910
export class LeetCodeNode {
@@ -13,8 +14,8 @@ export class LeetCodeNode {
1314
return this.data.name;
1415
}
1516

16-
public get solved(): boolean {
17-
return this.data.solved;
17+
public get state(): ProblemState {
18+
return this.data.state;
1819
}
1920

2021
public get id(): string {
@@ -64,11 +65,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
6465
id: `${idPrefix}.${element.id}`,
6566
collapsibleState: element.isProblem ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed,
6667
contextValue: element.isProblem ? "problem" : "difficulty",
67-
iconPath: element.isProblem ?
68-
(element.solved ?
69-
this.context.asAbsolutePath(path.join("resources", "check.png"))
70-
: this.context.asAbsolutePath(path.join("resources", "blank.png")))
71-
: "",
68+
iconPath: this.parseIconPathFromProblemState(element),
7269
};
7370
}
7471

@@ -77,7 +74,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
7774
return [
7875
new LeetCodeNode(
7976
{
80-
solved: false,
77+
state: ProblemState.Unknown,
8178
id: "notSignIn",
8279
name: "Sign in to LeetCode",
8380
difficulty: "",
@@ -128,7 +125,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
128125
difficultynodes.push(
129126
new LeetCodeNode(
130127
{
131-
solved: false,
128+
state: ProblemState.Unknown,
132129
id: difficulty,
133130
name: difficulty,
134131
difficulty: "",
@@ -155,4 +152,20 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
155152
});
156153
return difficultynodes;
157154
}
155+
156+
private parseIconPathFromProblemState(element: LeetCodeNode): string {
157+
if (!element.isProblem) {
158+
return "";
159+
}
160+
switch (element.state) {
161+
case ProblemState.AC:
162+
return this.context.asAbsolutePath(path.join("resources", "check.png"));
163+
case ProblemState.NotAC:
164+
return this.context.asAbsolutePath(path.join("resources", "x.png"));
165+
case ProblemState.Unknown:
166+
return this.context.asAbsolutePath(path.join("resources", "blank.png"));
167+
default:
168+
return "";
169+
}
170+
}
158171
}

src/shared.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ export const languages = [
3030
"scala",
3131
"swift",
3232
];
33+
34+
export enum ProblemState {
35+
AC = 1,
36+
NotAC = 2,
37+
Unknown = 3,
38+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy