|
7 | 7 | * Copyright (c) 2022 ccagml . All rights reserved.
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import * as fse from "fs-extra"; |
| 10 | +import * as fs from "fs"; |
11 | 11 | import * as _ from "lodash";
|
12 | 12 | import * as path from "path";
|
13 | 13 | import { IProblem, langExt } from "../model/Model";
|
14 | 14 | import { executeCommand } from "./CliUtils";
|
15 | 15 | import { isUseVscodeNode, isUseWsl } from "./ConfigUtils";
|
16 | 16 | import { Uri, window, TextEditor } from "vscode";
|
| 17 | +import { fileMeta, ProblemMeta } from "../utils/problemUtils"; |
17 | 18 |
|
18 | 19 | export function isWindows(): boolean {
|
19 | 20 | return process.platform === "win32";
|
@@ -58,12 +59,10 @@ export function genFileName(node: IProblem, language: string): string {
|
58 | 59 | }
|
59 | 60 |
|
60 | 61 | export async function getNodeIdFromFile(fsPath: string): Promise<string> {
|
61 |
| - const fileContent: string = await fse.readFile(fsPath, "utf8"); |
62 |
| - let id: string = ""; |
63 |
| - const matchResults: RegExpMatchArray | null = fileContent.match(/@lc.+id=(.+?) /); |
64 |
| - if (matchResults && matchResults.length === 2) { |
65 |
| - id = matchResults[1]; |
66 |
| - } |
| 62 | + const fileContent: Buffer = fs.readFileSync(fsPath); |
| 63 | + const meta: ProblemMeta | null = fileMeta(fileContent.toString()); |
| 64 | + |
| 65 | + let id = meta?.id; |
67 | 66 | // Try to get id from file name if getting from comments failed
|
68 | 67 | if (!id) {
|
69 | 68 | id = path.basename(fsPath).split(".")[0];
|
|
0 commit comments