Skip to content

Support locked problems #19

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 2 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
{
"title": "LeetCode",
"properties": {
"leetcode.showLocked": {
"type": "boolean",
"default": false,
"description": "Show locked problems."
},
"leetcode.defaultLanguage": {
"type": "string",
"enum": [
Expand Down
Binary file added resources/lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 14 additions & 8 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { executeCommand } from "../utils/cpUtils";
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";

export interface IProblem {
favorite: boolean;
locked: boolean;
state: ProblemState;
id: string;
name: string;
Expand All @@ -19,19 +21,23 @@ export async function listProblems(channel: vscode.OutputChannel): Promise<IProb
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
return [];
}
const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "list", "-q", "L"]);
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
const showLocked: boolean | undefined = leetCodeConfig.get<boolean>("showLocked");
const result: string = await executeCommand(channel, "node", showLocked ? [leetCodeBinaryPath, "list"] : [leetCodeBinaryPath, "list", "-q", "L"]);
const problems: IProblem[] = [];
const lines: string[] = result.split("\n");
const reg: RegExp = /(.?)\s*\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
for (const line of lines) {
const match: RegExpMatchArray | null = line.match(reg);
if (match && match.length === 6) {
if (match && match.length === 8) {
problems.push({
state: parseProblemState(match[1]),
id: match[2].trim(),
name: match[3].trim(),
difficulty: match[4].trim(),
passRate: match[5].trim(),
favorite: 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(),
});
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function parseProblemsToPicks(p: Promise<list.IProblem[]>): Promise<Array<
const picks: Array<IQuickItemEx<string>> = (await p).map((problem: list.IProblem) => Object.assign({}, {
label: `${parseProblemDecorator(problem.state)}${problem.id}.${problem.name}`,
description: "",
detail: `AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
detail: `${parseLockDecorator(problem.locked)}AC rate: ${problem.passRate}, Difficulty: ${problem.difficulty}`,
value: problem.id,
}));
resolve(picks);
Expand All @@ -98,3 +98,7 @@ function parseProblemDecorator(state: ProblemState): string {
return "";
}
}

function parseLockDecorator(locked: boolean): string {
return locked ? "$(lock) " : "";
}
10 changes: 10 additions & 0 deletions src/leetCodeExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { ProblemState } from "./shared";
export class LeetCodeNode {
constructor(private data: list.IProblem, private isProblemNode = true) { }

public get locked(): boolean {
return this.data.locked;
}
public get name(): string {
return this.data.name;
}
Expand Down Expand Up @@ -74,6 +77,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
return [
new LeetCodeNode(
{
favorite: false,
locked: false,
state: ProblemState.Unknown,
id: "notSignIn",
name: "Sign in to LeetCode",
Expand Down Expand Up @@ -125,6 +130,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
difficultynodes.push(
new LeetCodeNode(
{
favorite: false,
locked: false,
state: ProblemState.Unknown,
id: difficulty,
name: difficulty,
Expand Down Expand Up @@ -163,6 +170,9 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
case ProblemState.NotAC:
return this.context.asAbsolutePath(path.join("resources", "x.png"));
case ProblemState.Unknown:
if (element.locked) {
return this.context.asAbsolutePath(path.join("resources", "lock.png"));
}
return this.context.asAbsolutePath(path.join("resources", "blank.png"));
default:
return "";
Expand Down