MCPcopy Index your code
hub / github.com/LeetCode-OpenSource/vscode-leetcode / listProblems

Function listProblems

src/commands/list.ts:11–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
10
11export async function listProblems(): Promise<IProblem[]> {
12 try {
13 if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
14 return [];
15 }
16 const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
17 const showLocked: boolean = !!leetCodeConfig.get<boolean>("showLocked");
18 const useEndpointTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
19 const result: string = await leetCodeExecutor.listProblems(showLocked, useEndpointTranslation);
20 const problems: IProblem[] = [];
21 const lines: string[] = result.split("\n");
22 const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
23 const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
24 for (const line of lines) {
25 const match: RegExpMatchArray | null = line.match(reg);
26 if (match && match.length === 8) {
27 const id: string = match[4].trim();
28 problems.push({
29 id,
30 isFavorite: match[1].trim().length > 0,
31 locked: match[2].trim().length > 0,
32 state: parseProblemState(match[3]),
33 name: match[5].trim(),
34 difficulty: match[6].trim(),
35 passRate: match[7].trim(),
36 companies: companies[id] || ["Unknown"],
37 tags: tags[id] || ["Unknown"],
38 });
39 }
40 }
41 return problems.reverse();
42 } catch (error) {
43 await promptForOpenOutputChannel("Failed to list problems. Please open the output channel for details.", DialogType.error);
44 return [];
45 }
46}
47
48function parseProblemState(stateOutput: string): ProblemState {
49 if (!stateOutput) {

Callers

nothing calls this directly

Calls 5

parseProblemStateFunction · 0.85
getStatusMethod · 0.80
listProblemsMethod · 0.80
getCompaniesAndTagsMethod · 0.80

Tested by

no test coverage detected