From 681136e784fef4aa1c1ef6a186cc3894e9599ae0 Mon Sep 17 00:00:00 2001 From: sunerpy Date: Thu, 24 Jul 2025 16:54:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(datacollector):=20=E6=B7=BB=E5=8A=A0=20json?= =?UTF-8?q?c-parser=20=E4=BE=9D=E8=B5=96=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=A7=A3=E6=9E=90,=E4=BF=AE=E5=A4=8Dsettings?= =?UTF-8?q?.json=E4=B8=AD=E7=9A=84=E6=B3=A8=E9=87=8A=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 package.json 中添加 jsonc-parser 依赖 - 更新 pnpm-lock.yaml 文件以反映新依赖 - 修改 dataCollector.ts 中的配置解析逻辑,使用 jsonc-parser 替代原生 JSON.parse --- package.json | 5 ++++- pnpm-lock.yaml | 4 ++++ src/dataCollector.ts | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4c04bdb..151751e 100644 --- a/package.json +++ b/package.json @@ -168,5 +168,8 @@ "prettier": "3.6.2", "typescript": "^5.8.3" }, - "packageManager": "pnpm@9.4.0+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a" + "packageManager": "pnpm@9.4.0+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a", + "dependencies": { + "jsonc-parser": "^3.3.1" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 78502f8..ae5d763 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,10 @@ settings: importers: .: + dependencies: + jsonc-parser: + specifier: ^3.3.1 + version: 3.3.1 devDependencies: '@types/mocha': specifier: ^10.0.10 diff --git a/src/dataCollector.ts b/src/dataCollector.ts index 874f924..6361dd7 100644 --- a/src/dataCollector.ts +++ b/src/dataCollector.ts @@ -17,6 +17,7 @@ import { getPlatform, } from './utils/vscodeEnvironment'; import { VSCodeEdition, Platform } from './types/vscodeEdition'; +import * as jsonc from 'jsonc-parser'; export class DataCollector { public readonly vscodeEdition: VSCodeEdition; @@ -101,7 +102,6 @@ export class DataCollector { } async getSettings(): Promise { - const config = vscode.workspace.getConfiguration(); const settings: SettingsExport = {}; // 获取用户设置 @@ -220,7 +220,7 @@ export class DataCollector { const settingsPath = this.getUserSettingsPath(); if (fs.existsSync(settingsPath)) { const content = fs.readFileSync(settingsPath, 'utf8'); - return JSON.parse(content); + return jsonc.parse(content); } } catch (error) { if (this.outputChannel) { @@ -237,7 +237,7 @@ export class DataCollector { const settingsPath = path.join(workspaceFolder.uri.fsPath, '.vscode', 'settings.json'); if (fs.existsSync(settingsPath)) { const content = fs.readFileSync(settingsPath, 'utf8'); - return JSON.parse(content); + return jsonc.parse(content); } } } catch (error) {