diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d6bf4..8f1dee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# version 2.19.14 + +- 在 ID 含有空格的题目对应的文件中,点击 Description 按钮时,无法识别题目 ID + ## version 2.19.13 - 增加重试上次测试用例按钮 retest diff --git a/package.json b/package.json index 114e06c..313f700 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "%main.description%", - "version": "2.19.13", + "version": "2.19.14", "author": "ccagml", "publisher": "ccagml", "license": "MIT", diff --git a/src/utils/SystemUtils.ts b/src/utils/SystemUtils.ts index c65a615..802420f 100644 --- a/src/utils/SystemUtils.ts +++ b/src/utils/SystemUtils.ts @@ -7,13 +7,14 @@ * Copyright (c) 2022 ccagml . All rights reserved. */ -import * as fse from "fs-extra"; +import * as fs from "fs"; import * as _ from "lodash"; import * as path from "path"; import { IProblem, langExt } from "../model/Model"; import { executeCommand } from "./CliUtils"; import { isUseVscodeNode, isUseWsl } from "./ConfigUtils"; import { Uri, window, TextEditor } from "vscode"; +import { fileMeta, ProblemMeta } from "../utils/problemUtils"; export function isWindows(): boolean { return process.platform === "win32"; @@ -58,12 +59,10 @@ export function genFileName(node: IProblem, language: string): string { } export async function getNodeIdFromFile(fsPath: string): Promise { - const fileContent: string = await fse.readFile(fsPath, "utf8"); - let id: string = ""; - const matchResults: RegExpMatchArray | null = fileContent.match(/@lc.+id=(.+?) /); - if (matchResults && matchResults.length === 2) { - id = matchResults[1]; - } + const fileContent: Buffer = fs.readFileSync(fsPath); + const meta: ProblemMeta | null = fileMeta(fileContent.toString()); + + let id = meta?.id; // Try to get id from file name if getting from comments failed if (!id) { id = path.basename(fsPath).split(".")[0];