8000 Support locked problems (#19) · SShnoodles/vscode-leetcode@f3946b9 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3946b9

Browse files
TsFreddiejdneo
authored andcommitted
Support locked problems (LeetCode-OpenSource#19)
1 parent f58422f commit f3946b9

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@
129129
{
130130
"title": "LeetCode",
131131
"properties": {
132+
"leetcode.showLocked": {
133+
"type": "boolean",
134+
"default": false,
135+
"description": "Show locked problems."
136+
},
132137
"leetcode.defaultLanguage": {
133138
"type": "string",
134139
"enum": [

resources/lock.png

2.49 KB
Loading

src/commands/list.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { executeCommand } from "../utils/cpUtils";
77
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
88

99
export interface IProblem {
10+
favorite: boolean;
11+
locked: boolean;
1012
state: ProblemState;
1113
id: string;
1214
name: string;
@@ -19,19 +21,23 @@ export async function listProblems(channel: vscode.OutputChannel): Promise<IProb
1921
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
2022
return [];
2123
}
22-
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "list", "-q", "L"]);
24+
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
25+
const showLocked: boolean | undefined = leetCodeConfig.get<boolean>("showLocked");
26+
const result: string = await executeCommand(channel, "node", showLocked ? [leetCodeBinaryPath, "list"] : [leetCodeBinaryPath, "list", "-q", "L"]);
2327
const problems: IProblem[] = [];
2428
const lines: string[] = result.split("\n");
25-
const reg: RegExp = /(.?)\s*\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
29+
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
2630
for (const line of lines) {
2731
const match: RegExpMatchArray | null = line.match(reg);
28-
if (match && match.length === 6) {
32+
if (match && match.length === 8) {
2933
problems.push({
30-
state: parseProblemState(match[1]),
31-
id: match[2].trim(),
32-
name: match[3].trim(),
33-
difficulty: match[4].trim(),
34-
passRate: match[5].trim(),
34+
favorite: match[1].trim().length > 0,
35+
locked: match[2].trim().length > 0,
36+
state: parseProblemState(match[3]),
37+
id: match[4].trim(),
38+
name: match[5].trim(),
39+
difficulty: match[6].trim(),
40+
passRate: match[7].trim(),
3541
});
3642
}
3743
}

src/commands/show.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async function parseProblemsToPicks(p: Promise<list.IProblem[]>): Promise<Array<
8181
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: list.IProblem) => Object.assign({}, {
8282
label: `${parseProblemDecorator(problem.state)}${problem.id}.${problem.name}`,
8383
description: "",
84-
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
84+
detail: `${parseLockDecorator(problem.locked)}AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
8585
value: problem.id,
8686
}));
8787
resolve(picks);
@@ -98,3 +98,7 @@ function parseProblemDecorator(state: ProblemState): string {
9898
return "";
9999
}
100100
}
101+
102+
function parseLockDecorator(locked: boolean): string {
103+
return locked ? "$(lock) " : "";
104+
}

src/leetCodeExplorer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { ProblemState } from "./shared";
1010
export class LeetCodeNode {
1111
constructor(private data: list.IProblem, private isProblemNode = true) { }
1212

13+
public get locked(): boolean {
14+
return this.data.locked;
15+
}
1316
public get name(): string {
1417
return this.data.name;
1518
}
@@ -74,6 +77,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
7477
return [
7578
new LeetCodeNode(
7679
{
80+
favorite: false,
81+
locked: false,
7782
state: ProblemState.Unknown,
7883
id: "notSignIn",
7984
name: "Sign in to LeetCode",
@@ -125,6 +130,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
125130
difficultynodes.push(
126131
new LeetCodeNode(
127132
{
133+
favorite: false,
134+
locked: false,
128135
state: ProblemState.Unknown,
129136
id: difficulty,
130137
name: difficulty,
@@ -163,6 +170,9 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
163170
case ProblemState.NotAC:
164171
return this.context.asAbsolutePath(path.join("resources", "x.png"));
165172
case ProblemState.Unknown:
173+
if (element.locked) {
174+
return this.context.asAbsolutePath(path.join("resources", "lock.png"));
175+
}
166176
return this.context.asAbsolutePath(path.join("resources", "blank.png"));
167177
default:
168178
return "";

0 commit comments

Comments
 (0)
0