Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Add companies and tags information to IProblem
(from direct import of leetcode-cli company plugin)
  • Loading branch information
Vigilans committed Jan 22, 2019
commit ce204b9875201b935de75f58576238d6d90e80ac
15 changes: 14 additions & 1 deletion src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import * as path from "path";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { ProblemState, UserStatus } from "../shared";
Expand All @@ -15,6 +16,8 @@ export interface IProblem {
name: string;
difficulty: string;
passRate: string;
tags: string[];
companies: string[];
}

export async function listProblems(): Promise<IProblem[]> {
Expand All @@ -28,17 +31,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 getCompaniesAndTags();
for (const line of lines) {
const match: RegExpMatchArray | null = line.match(reg);
if (match && match.length === 8) {
const id = match[4].trim();
problems.push({
favorite: match[1].trim().length > 0,
locked: match[2].trim().length > 0,
state: parseProblemState(match[3]),
id: match[4].trim(),
id: id,
name: match[5].trim(),
difficulty: match[6].trim(),
passRate: match[7].trim(),
companies: companies[id],
tags: tags[id]
});
}
}
Expand Down Expand Up @@ -66,3 +73,9 @@ function parseProblemState(stateOutput: string): ProblemState {
return ProblemState.Unknown;
}
}

async function getCompaniesAndTags(): Promise<{ companies: { [key: string]: string[] }, tags: { [key: string]: string[] } }> {
const COMPONIES_TAGS_PATH = path.join(await leetCodeExecutor.getLeetCodeRootPath(), "lib", "plugins", "company.js");
const { COMPONIES, TAGS } = require(COMPONIES_TAGS_PATH);
return { companies: COMPONIES, tags: TAGS };
}
4 changes: 4 additions & 0 deletions src/leetCodeExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
name: "Sign in to LeetCode",
difficulty: "",
passRate: "",
companies: [],
tags: []
},
false,
),
Expand Down Expand Up @@ -138,6 +140,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
name: difficulty,
difficulty: "",
passRate: "",
companies: [],
tags: []
},
false,
),
Expand Down