Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 78c759a

Browse files
committed
fix<filePath>: just translate question, but use eng name when new file.
1. 向IProblem增加enName字段,额外获取英文版本问题名 2. 增加${snake_case_name_en}, 读取英文问题名并使用驼峰命名
1 parent d713ad5 commit 78c759a

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/commands/list.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,50 @@ export async function listProblems(): Promise<IProblem[]> {
1717
const showLocked: boolean = !!leetCodeConfig.get<boolean>("showLocked");
1818
const useEndpointTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
1919
const result: string = await leetCodeExecutor.listProblems(showLocked, useEndpointTranslation);
20+
const resultE: string = await leetCodeExecutor.listProblems(showLocked, false);
2021
const problems: IProblem[] = [];
2122
const lines: string[] = result.split("\n");
23+
const linesE: string[] = resultE.split("\n");
2224
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
2325
const { companies, tags } = await leetCodeExecutor.getCompaniesAndTags();
24-
for (const line of lines) {
26+
for (let i = 0; i < lines.length; i++) {
27+
const line: string = lines[i]
28+
const lineE: string = linesE[i]
2529
const match: RegExpMatchArray | null = line.match(reg);
26-
if (match && match.length === 8) {
30+
const matchE: RegExpMatchArray | null = lineE.match(reg);
31+
if (match && match.length === 8 && matchE && matchE.length === 8) {
2732
const id: string = match[4].trim();
2833
problems.push({
2934
id,
3035
isFavorite: match[1].trim().length > 0,
3136
locked: match[2].trim().length > 0,
3237
state: parseProblemState(match[3]),
3338
name: match[5].trim(),
39+
enName: matchE[5].trim(),
3440
difficulty: match[6].trim(),
3541
passRate: match[7].trim(),
3642
companies: companies[id] || ["Unknown"],
3743
tags: tags[id] || ["Unknown"],
3844
});
3945
}
4046
}
47+
// for (const line of lines) {
48+
// const match: RegExpMatchArray | null = line.match(reg);
49+
// if (match && match.length === 8) {
50+
// const id: string = match[4].trim();
51+
// problems.push({
52+
// id,
53+
// isFavorite: match[1].trim().length > 0,
54+
// locked: match[2].trim().length > 0,
55+
// state: parseProblemState(match[3]),
56+
// name: match[5].trim(),
57+
// difficulty: match[6].trim(),
58+
// passRate: match[7].trim(),
59+
// companies: companies[id] || ["Unknown"],
60+
// tags: tags[id] || ["Unknown"],
61+
// });
62+
// }
63+
// }
4164
return problems.reverse();
4265
} catch (error) {
4366
await promptForOpenOutputChannel("Failed to list problems. Please open the output channel for details.", DialogType.error);

src/commands/show.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ async function resolveRelativePath(relativePath: string, node: IProblem, selecte
244244
case "snakecasename":
245245
case "snake_case_name":
246246
return _.snakeCase(node.name);
247+
case "snake_case_name_en":
248+
return _.snakeCase(node.enName);
247249
case "ext":
248250
return genFileExt(selectedLanguage);
249251
case "language":

src/explorer/LeetCodeNode.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ export class LeetCodeNode {
1111
public get locked(): boolean {
1212
return this.data.locked;
1313
}
14+
1415
public get name(): string {
1516
return this.data.name;
1617
}
1718

19+
public get enName(): string {
20+
return this.data.enName;
21+
}
22+
1823
public get state(): ProblemState {
1924
return this.data.state;
2025
}

src/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface IProblem {
7676
state: ProblemState;
7777
id: string;
7878
name: string;
79+
enName: string;
7980
difficulty: string;
8081
passRate: string;
8182
companies: string[];
@@ -88,6 +89,7 @@ export const defaultProblem: IProblem = {
8889
state: ProblemState.Unknown,
8990
id: "",
9091
name: "",
92+
enName: "",
9193
difficulty: "",
9294
passRate: "",
9395
companies: [] as string[],

0 commit comments

Comments
 (0)