Skip to content

Commit c05a417

Browse files
authored
fix(datacollector): 添加 jsonc-parser 依赖并优化配置解析,修复settings.json中的注释解析失败的问题 (#18)
- 在 package.json 中添加 jsonc-parser 依赖 - 更新 pnpm-lock.yaml 文件以反映新依赖 - 修改 dataCollector.ts 中的配置解析逻辑,使用 jsonc-parser 替代原生 JSON.parse
1 parent a7c1ac9 commit c05a417

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,8 @@
168168
"prettier": "3.6.2",
169169
"typescript": "^5.8.3"
170170
},
171-
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
171+
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a",
172+
"dependencies": {
173+
"jsonc-parser": "^3.3.1"
174+
}
172175
}

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dataCollector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getPlatform,
1818
} from './utils/vscodeEnvironment';
1919
import { VSCodeEdition, Platform } from './types/vscodeEdition';
20+
import * as jsonc from 'jsonc-parser';
2021

2122
export class DataCollector {
2223
public readonly vscodeEdition: VSCodeEdition;
@@ -101,7 +102,6 @@ export class DataCollector {
101102
}
102103

103104
async getSettings(): Promise<SettingsExport> {
104-
const config = vscode.workspace.getConfiguration();
105105
const settings: SettingsExport = {};
106106

107107
// 获取用户设置
@@ -220,7 +220,7 @@ export class DataCollector {
220220
const settingsPath = this.getUserSettingsPath();
221221
if (fs.existsSync(settingsPath)) {
222222
const content = fs.readFileSync(settingsPath, 'utf8');
223-
return JSON.parse(content);
223+
return jsonc.parse(content);
224224
}
225225
} catch (error) {
226226
if (this.outputChannel) {
@@ -237,7 +237,7 @@ export class DataCollector {
237237
const settingsPath = path.join(workspaceFolder.uri.fsPath, '.vscode', 'settings.json');
238238
if (fs.existsSync(settingsPath)) {
239239
const content = fs.readFileSync(settingsPath, 'utf8');
240-
return JSON.parse(content);
240+
return jsonc.parse(content);
241241
}
242242
}
243243
} catch (error) {

0 commit comments

Comments
 (0)