Skip to content

Enhanced Tree view #94

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 14 commits into from
Feb 2, 2019
55 changes: 33 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@
{
"title": "LeetCode",
"properties": {
"leetcode.hideSolved": {
"type": "boolean",
"default": false,
"scope": "application",
"description": "Hide solved problems."
},
"leetcode.showLocked": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -258,12 +264,14 @@
"@types/fs-extra": "5.0.0",
"@types/mocha": "^2.2.42",
"@types/node": "^7.0.43",
"@types/require-from-string": "^1.2.0",
"tslint": "^5.9.1",
"typescript": "^2.6.1",
"vscode": "^1.1.22"
},
"dependencies": {
"fs-extra": "^6.0.1",
"leetcode-cli": "2.6.1"
"leetcode-cli": "2.6.1",
"require-from-string": "^2.0.2"
}
}
20 changes: 7 additions & 13 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@
import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { ProblemState, UserStatus } from "../shared";
import { IProblem, ProblemState, UserStatus } from "../shared";
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";

export interface IProblem {
favorite: boolean;
locked: boolean;
state: ProblemState;
id: string;
name: string;
difficulty: string;
passRate: string;
}

export async function listProblems(): Promise<IProblem[]> {
try {
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
Expand All @@ -28,17 +18,21 @@ export async function listProblems(): Promise<IProblem[]> {
const problems: IProblem[] = [];
const lines: string[] = result.split("\n");
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
for (const line of lines) {
const match: RegExpMatchArray | null = line.match(reg);
if (match && match.length === 8) {
const id: string = match[4].trim();
problems.push({
favorite: match[1].trim().length > 0,
id,
isFavorite: match[1].trim().length > 0,
locked: match[2].trim().length > 0,
state: parseProblemState(match[3]),
id: match[4].trim(),
name: match[5].trim(),
difficulty: match[6].trim(),
passRate: match[7].trim(),
companies: companies[id] || ["Unknown"],
tags: tags[id] || ["Unknown"],
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import * as fse from "fs-extra";
import * as vscode from "vscode";
import { LeetCodeNode } from "../explorer/LeetCodeNode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { LeetCodeNode } from "../leetCodeExplorer";
import { leetCodeManager } from "../leetCodeManager";
import { IQuickItemEx, languages, ProblemState } from "../shared";
import { IProblem, IQuickItemEx, languages, ProblemState } from "../shared";
import { DialogOptions, DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { selectWorkspaceFolder } from "../utils/workspaceUtils";
import * as wsl from "../utils/wslUtils";
Expand Down Expand Up @@ -80,9 +80,9 @@ async function showProblemInternal(id: string): Promise<void> {
}
}

async function parseProblemsToPicks(p: Promise<list.IProblem[]>): Promise<Array<IQuickItemEx<string>>> {
async function parseProblemsToPicks(p: Promise<IProblem[]>): Promise<Array<IQuickItemEx<string>>> {
return new Promise(async (resolve: (res: Array<IQuickItemEx<string>>) => void): Promise<void> => {
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: list.IProblem) => Object.assign({}, {
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: IProblem) => Object.assign({}, {
label: `${parseProblemDecorator(problem.state, problem.locked)}${problem.id}.${problem.name}`,
description: "",
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
Expand Down
51 changes: 51 additions & 0 deletions src/explorer/LeetCodeNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import { IProblem, ProblemState } from "../shared";

export class LeetCodeNode {
constructor(private data: IProblem, private parentNodeName: string, private isProblemNode: boolean = true) { }

public get locked(): boolean {
return this.data.locked;
}
public get name(): string {
return this.data.name;
}

public get state(): ProblemState {
return this.data.state;
}

public get id(): string {
return this.data.id;
}

public get passRate(): string {
return this.data.passRate;
}

public get difficulty(): string {
return this.data.difficulty;
}

public get tags(): string[] {
return this.data.tags;
}

public get companies(): string[] {
return this.data.companies;
}

public get isFavorite(): boolean {
return this.data.isFavorite;
}

public get isProblem(): boolean {
return this.isProblemNode;
}

public get parentName(): string {
return this.parentNodeName;
}
}
Loading