From 832f8a3d3396c0b07b5a3907772fbfcc222410d9 Mon Sep 17 00:00:00 2001 From: Freddie Wang Date: Thu, 8 Mar 2018 21:05:13 -0800 Subject: [PATCH 1/2] Support locked problems --- package.json | 5 +++++ resources/lock.png | Bin 0 -> 2550 bytes src/commands/list.ts | 22 ++++++++++++++-------- src/commands/show.ts | 6 +++++- src/leetCodeExplorer.ts | 10 ++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 resources/lock.png diff --git a/package.json b/package.json index 822fe441..bcef2d8f 100644 --- a/package.json +++ b/package.json @@ -129,6 +129,11 @@ { "title": "LeetCode", "properties": { + "leetcode.showLocked": { + "type": "boolean", + "default": true, + "description": "Show locked problems." + }, "leetcode.defaultLanguage": { "type": "string", "enum": [ diff --git a/resources/lock.png b/resources/lock.png new file mode 100644 index 0000000000000000000000000000000000000000..96780dada2edbb13f2d7847825036bd925069bd8 GIT binary patch literal 2550 zcmbVO3se;49-oEfrD778ilWn4kml?>_5nMwymmpnHiRRaEFyEG#LC#m6bQaEzFa#P=cVbk;bvd($K76=QQOm4?sguVsg2MW{No(wsTJ2Z9@8vet^I{YeEY2R@~|_b47ec zrO3^%%&{?*#f*_fl9S-XataW*IGKjaT_tXbDmNisUJ8tr*BAnOA#$+^NmT^lLTesu z7DNu#YYZqu=x{jRs38ovPEX8%Nt}qsa6N__P@JIf1d1eJ-wy$5BI}^?Esy)Oz>^6n zl4TEtVP$1ynli0M5S?(ndxQ&VKf*}QbTynwOXl6wKDYd?xVL~Qno%0lgfL1)ax4N5zvl0elRxFX zZ+%%22S|UXQio+E!6BE?BA4m}`TN68P&`*02a)@^@e;k__f7wEz6Ny-1O>)r zT2gI=&z^cEIXiNB)S2Y3Z#3Ah=bU;I7RN-dJzcjR*BMT>w5%H+yQzDboh6sOKvieR zEeTUwK3S)FLpzJcHNlbk$6vgV+-O_(X!GaAU5U>xS^d$2rY!^3zFXh^bi7aMyR@`L zXWd>nr)hRdXx@V90mz2jO~y|nHw3+K>imSZu;#aGDfP|SNyh$vL-yqdCLLB+fAX(g zu@2|%C!ajQKG=|UcKpJjkJ}GkbgfoneuJAr?fc*8{!j~%+5 zyQcl%n`hs74KXPg9Jc25 z878rnDeZp0yViBkWLh;5u1*@i5)V)i0 z(qr@X_YO9Y~umBu9-5DI) zdVJCU?w@`6D|NxP{7ov&^b6$)o~e8H*EK%0>vUZ2P+UPz4>WYAzh**GfcomY>h%Hh z8kfAhwE5bN=%+3lgR*-99zF2TXGhhZ&bEC!?3%5?#aEtd`p+{Vg{2V>6z{^$O_@9x z;E8RFNUU4vJd>>cE@@`_c?@kjb2%&Vy`frDNBEgVQ=?N!G-_gpuIlvGpn#CCCw;zp z?SSsWoWmi|gre4qKQyUU)knCVz6I@0UwlPhRkk#%O-l*6aOh&}#mQ}R2c(J9 eevA?7ehO~MC$GEvEAx~uv&{4yOH("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(), + favorate: 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(), }); } } diff --git a/src/commands/show.ts b/src/commands/show.ts index b8ce98b5..081a6bd2 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -81,7 +81,7 @@ async function parseProblemsToPicks(p: Promise): Promise> = (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); @@ -98,3 +98,7 @@ function parseProblemDecorator(state: ProblemState): string { return ""; } } + +function parseLockDecorator(locked: boolean): string { + return locked ? "$(lock) " : ""; +} diff --git a/src/leetCodeExplorer.ts b/src/leetCodeExplorer.ts index 9f26bbeb..927fb5fb 100644 --- a/src/leetCodeExplorer.ts +++ b/src/leetCodeExplorer.ts @@ -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; } @@ -74,6 +77,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider Date: Fri, 9 Mar 2018 09:10:22 -0800 Subject: [PATCH 2/2] Fixed a typo, added a type def --- package.json | 2 +- src/commands/list.ts | 6 +++--- src/leetCodeExplorer.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bcef2d8f..dfd17b6a 100644 --- a/package.json +++ b/package.json @@ -131,7 +131,7 @@ "properties": { "leetcode.showLocked": { "type": "boolean", - "default": true, + "default": false, "description": "Show locked problems." }, "leetcode.defaultLanguage": { diff --git a/src/commands/list.ts b/src/commands/list.ts index df9a9c2d..600335d0 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -7,7 +7,7 @@ import { executeCommand } from "../utils/cpUtils"; import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils"; export interface IProblem { - favorate: boolean; + favorite: boolean; locked: boolean; state: ProblemState; id: string; @@ -22,7 +22,7 @@ export async function listProblems(channel: vscode.OutputChannel): Promise("showLocked"); + const showLocked: boolean | undefined = leetCodeConfig.get("showLocked"); const result: string = await executeCommand(channel, "node", showLocked ? [leetCodeBinaryPath, "list"] : [leetCodeBinaryPath, "list", "-q", "L"]); const problems: IProblem[] = []; const lines: string[] = result.split("\n"); @@ -31,7 +31,7 @@ export async function listProblems(channel: vscode.OutputChannel): Promise 0, + favorite: match[1].trim().length > 0, locked: match[2].trim().length > 0, state: parseProblemState(match[3]), id: match[4].trim(), diff --git a/src/leetCodeExplorer.ts b/src/leetCodeExplorer.ts index 927fb5fb..09dc7cff 100644 --- a/src/leetCodeExplorer.ts +++ b/src/leetCodeExplorer.ts @@ -77,7 +77,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider