Skip to content

Commit 24a59a3

Browse files
Vigilansjdneo
authored andcommitted
Support categorize the problem according to: Company, Difficulty, Tag & Favorite (#94)
1 parent 19fe753 commit 24a59a3

11 files changed

+411
-233
lines changed

package-lock.json

+33-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@
193193
{
194194
"title": "LeetCode",
195195
"properties": {
196+
"leetcode.hideSolved": {
197+
"type": "boolean",
198+
"default": false,
199+
"scope": "application",
200+
"description": "Hide solved problems."
201+
},
196202
"leetcode.showLocked": {
197203
"type": "boolean",
198204
"default": false,
@@ -258,12 +264,14 @@
258264
"@types/fs-extra": "5.0.0",
259265
"@types/mocha": "^2.2.42",
260266
"@types/node": "^7.0.43",
267+
"@types/require-from-string": "^1.2.0",
261268
"tslint": "^5.9.1",
262269
"typescript": "^2.6.1",
263270
"vscode": "^1.1.22"
264271
},
265272
"dependencies": {
266273
"fs-extra": "^6.0.1",
267-
"leetcode-cli": "2.6.1"
274+
"leetcode-cli": "2.6.1",
275+
"require-from-string": "^2.0.2"
268276
}
269277
}

src/commands/list.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
import * as vscode from "vscode";
55
import { leetCodeExecutor } from "../leetCodeExecutor";
66
import { leetCodeManager } from "../leetCodeManager";
7-
import { ProblemState, UserStatus } from "../shared";
7+
import { IProblem, ProblemState, UserStatus } from "../shared";
88
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
99

10-
export interface IProblem {
11-
favorite: boolean;
12-
locked: boolean;
13-
state: ProblemState;
14-
id: string;
15-
name: string;
16-
difficulty: string;
17-
passRate: string;
18-
}
19-
2010
export async function listProblems(): Promise<IProblem[]> {
2111
try {
2212
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
@@ -28,17 +18,21 @@ export async function listProblems(): Promise<IProblem[]> {
2818
const problems: IProblem[] = [];
2919
const lines: string[] = result.split("\n");
3020
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
21+
const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
3122
for (const line of lines) {
3223
const match: RegExpMatchArray | null = line.match(reg);
3324
if (match && match.length === 8) {
25+
const id: string = match[4].trim();
3426
problems.push({
35-
favorite: match[1].trim().length > 0,
27+
id,
28+
isFavorite: match[1].trim().length > 0,
3629
locked: match[2].trim().length > 0,
3730
state: parseProblemState(match[3]),
38-
id: match[4].trim(),
3931
name: match[5].trim(),
4032
difficulty: match[6].trim(),
4133
passRate: match[7].trim(),
34+
companies: companies[id] || ["Unknown"],
35+
tags: tags[id] || ["Unknown"],
4236
});
4337
}
4438
}

src/commands/show.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import * as fse from "fs-extra";
55
import * as vscode from "vscode";
6+
import { LeetCodeNode } from "../explorer/LeetCodeNode";
67
import { leetCodeExecutor } from "../leetCodeExecutor";
7-
import { LeetCodeNode } from "../leetCodeExplorer";
88
import { leetCodeManager } from "../leetCodeManager";
9-
import { IQuickItemEx, languages, ProblemState } from "../shared";
9+
import { IProblem, IQuickItemEx, languages, ProblemState } from "../shared";
1010
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
1111
import { selectWorkspaceFolder } from "../utils/workspaceUtils";
1212
import * as wsl from "../utils/wslUtils";
@@ -80,9 +80,9 @@ async function showProblemInternal(id: string): Promise<void> {
8080
}
8181
}
8282

83-
async function parseProblemsToPicks(p: Promise<list.IProblem[]>): Promise<Array<IQuickItemEx<string>>> {
83+
async function parseProblemsToPicks(p: Promise<IProblem[]>): Promise<Array<IQuickItemEx<string>>> {
8484
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
85-
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: list.IProblem) => Object.assign({}, {
85+
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: IProblem) => Object.assign({}, {
8686
label: `${parseProblemDecorator(problem.state, problem.locked)}${problem.id}.${problem.name}`,
8787
description: "",
8888
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,

src/explorer/LeetCodeNode.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) jdneo. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import { IProblem, ProblemState } from "../shared";
5+
6+
export class LeetCodeNode {
7+
constructor(private data: IProblem, private parentNodeName: string, private isProblemNode: boolean = true) { }
8+
9+
public get locked(): boolean {
10+
return this.data.locked;
11+
}
12+
public get name(): string {
13+
return this.data.name;
14+
}
15+
16+
public get state(): ProblemState {
17+
return this.data.state;
18+
}
19+
20+
public get id(): string {
21+
return this.data.id;
22+
}
23+
24+
public get passRate(): string {
25+
return this.data.passRate;
26+
}
27+
28+
public get difficulty(): string {
29+
return this.data.difficulty;
30+
}
31+
32+
public get tags(): string[] {
33+
return this.data.tags;
34+
}
35+
36+
public get companies(): string[] {
37+
return this.data.companies;
38+
}
39+
40+
public get isFavorite(): boolean {
41+
return this.data.isFavorite;
42+
}
43+
44+
public get isProblem(): boolean {
45+
return this.isProblemNode;
46+
}
47+
48+
public get parentName(): string {
49+
return this.parentNodeName;
50+
}
51+
}

0 commit comments

Comments
 (0)