diff --git a/package.json b/package.json index 822fe441..dfd17b6a 100644 --- a/package.json +++ b/package.json @@ -129,6 +129,11 @@ { "title": "LeetCode", "properties": { + "leetcode.showLocked": { + "type": "boolean", + "default": false, + "description": "Show locked problems." + }, "leetcode.defaultLanguage": { "type": "string", "enum": [ diff --git a/resources/lock.png b/resources/lock.png new file mode 100644 index 00000000..96780dad Binary files /dev/null and b/resources/lock.png differ diff --git a/src/commands/list.ts b/src/commands/list.ts index 5fcd3d53..600335d0 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -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; @@ -19,19 +21,23 @@ export async function listProblems(channel: vscode.OutputChannel): Promise("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(), }); } } 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..09dc7cff 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