fix(vscode): allow comments in settings.json by parsing it as JSONC - #488
fix(vscode): allow comments in settings.json by parsing it as JSONC#488Nyx-abu wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for parsing JSONC files, specifically enabling it for VS Code configuration files by integrating the jsonc-parser library. The review feedback highlights a missing import of ReadJSONFileOptions in types.ts that will cause a TypeScript compilation error, and suggests utilizing printParseErrorCode to output human-readable error messages instead of raw numeric codes when JSONC parsing fails.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| protected getReadJSONFileOptions(): ReadJSONFileOptions | undefined { | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
The type ReadJSONFileOptions is referenced here but is not imported at the top of this file. This will cause a TypeScript compilation error. Please import it from @director.run/utilities/json at the top of the file:
import { readJSONFile, type ReadJSONFileOptions } from "@director.run/utilities/json";| if (options?.jsonc) { | ||
| const errors: any[] = []; | ||
| const parsed = parse(data, errors, { allowTrailingComma: true }); | ||
| if (errors.length > 0) { | ||
| throw new SyntaxError(`JSONC parse error: ${errors.map(e => e.error).join(', ')}`); | ||
| } | ||
| return parsed as T; | ||
| } |
There was a problem hiding this comment.
Currently, errors.map(e => e.error) will print raw numeric enum values (e.g., 1, 7) which are difficult to debug. We can use printParseErrorCode from jsonc-parser to convert these codes into human-readable strings.
Note: Please also update the import on line 6 to:
import { parse, printParseErrorCode, type ParseError } from "jsonc-parser";| if (options?.jsonc) { | |
| const errors: any[] = []; | |
| const parsed = parse(data, errors, { allowTrailingComma: true }); | |
| if (errors.length > 0) { | |
| throw new SyntaxError(`JSONC parse error: ${errors.map(e => e.error).join(', ')}`); | |
| } | |
| return parsed as T; | |
| } | |
| if (options?.jsonc) { | |
| const errors: ParseError[] = []; | |
| const parsed = parse(data, errors, { allowTrailingComma: true }); | |
| if (errors.length > 0) { | |
| throw new SyntaxError('JSONC parse error: ' + errors.map(e => printParseErrorCode(e.error)).join(', ')); | |
| } | |
| return parsed as T; | |
| } |
Hey!
This PR fixes #458, where director fails to parse settings.json if it contains comments (which VSCode allows natively via JSONC).
I added jsonc-parser as a dependency and updated the
eadJSONFile utility to accept a jsonc: true option. The VSCodeInstaller now overrides getReadJSONFileOptions to enable this, correctly parsing VSCode settings files even if they have comments.
Let me know if there's anything else you'd like me to tweak!