Skip to content

fix(vscode): allow comments in settings.json by parsing it as JSONC - #488

Open
Nyx-abu wants to merge 2 commits into
fdmtl:mainfrom
Nyx-abu:fix/vscode-jsonc
Open

fix(vscode): allow comments in settings.json by parsing it as JSONC#488
Nyx-abu wants to merge 2 commits into
fdmtl:mainfrom
Nyx-abu:fix/vscode-jsonc

Conversation

@Nyx-abu

@Nyx-abu Nyx-abu commented Jul 13, 2026

Copy link
Copy Markdown

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!

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +29 to +31
protected getReadJSONFileOptions(): ReadJSONFileOptions | undefined {
return undefined;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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";

Comment on lines +23 to +30
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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";
Suggested change
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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fails to install if my VSCode settings contain comments

1 participant