Skip to content

fix(editor): JSONC comments read as comments, not errors (#312) - #314

Merged
Maxaubert merged 2 commits into
mainfrom
fix/312-jsonc-comments
Oct 7, 2026
Merged

Maxaubert merged 2 commits into
mainfrom
fix/312-jsonc-comments

Conversation

@Maxaubert

Copy link
Copy Markdown
Owner

Closes #312.

Owner, 2026-10-07: "comments in jsonc arent read as comments in prism" (a wrangler.jsonc with a red squiggle under every // line, drawn in the plain text colour).

Cause

codeLang.ts mapped .jsonc and .json5 to the strict @codemirror/lang-json grammar, and CodeView attached jsonLinter (JSON.parse) to them. The Lezer JSON grammar has no comment token, so a comment became error nodes: no comment tag (so no comment colour, although codeTheme.ts maps t.comment / t.lineComment / t.blockComment to --p-code-comment) and a squiggle from both linters. tsconfig.json and other JSON-with-comments names went the same way through .json.

Fix

  • lib/jsoncMode.ts (new): a small StreamParser that emits the JSON grammar's own tags (propertyName, string, number, bool, null, brace, squareBracket, separator) plus lineComment / blockComment, with smart indent, comment tokens for Ctrl+/, and a brace fold service. A unit test holds that a comment-free document colours exactly as the JSON grammar colours it.
  • codeLint.ts: blankJsonc turns comments and trailing commas into spaces with every offset and line break kept, then jsoncErrors runs JSON.parse on the result, so a missing comma or an unclosed brace is still underlined at its real place; an unclosed /* is reported. lintFor(lang) decides the checker (JSON: grammar + JSON.parse; JSONC: jsoncErrors only; JSON5: none; stream lexers: none).
  • codeLang.ts: lint field on a language; JSONC for .jsonc, tsconfig.json, tsconfig.*.json, jsconfig.json, jsconfig.*.json, .eslintrc, .eslintrc.json, .babelrc, .babelrc.json, devcontainer.json, .devcontainer.json, wrangler.json, turbo.json, biome.json, deno.json, and every .json inside a .vscode folder (langFor(name, path)). .json5 colours the same with no linter (bare keys and single quotes would be false errors). Plain .json and .ipynb stay strict.
  • CodeView.tsx: langFor(name, path) and lintFor(lang) replace the inline regex.
  • No new dependency.

Files

  • src/renderer/src/lib/jsoncMode.ts (new)
  • src/renderer/src/lib/jsonc.test.ts (new, 13 tests)
  • src/renderer/src/lib/codeLang.ts
  • src/renderer/src/lib/codeLint.ts
  • src/renderer/src/components/CodeView.tsx
  • tools/e2e/run.mjs (jsonc scenario)
  • CLAUDE.md (rule with the owner's words)
  • package.json, package-lock.json (0.92.1 to 0.92.2)

Gates

  • npm run typecheck: clean
  • npm run lint: 0 errors (7 existing warnings, none in changed files)
  • npx vitest run: 171 files passed, 2539 tests passed (2 skipped)
  • New jsonc e2e: opens a wrangler.jsonc like the owner's, asserts no squiggles, every comment span wears the theme's comment colour (italic), tsconfig.json with comments and trailing commas is clean, and a missing comma in a .jsonc is underlined once. FAILS on main (6 failures, verified by running it against main's src), passes here. Screenshots .e2e/shots/jsonc.png, jsonc-error.png looked at.
  • Editor e2e one at a time: jsonc, code, treeNav, edit, reload, tail, md, previewClears all pass.
  • npm run e2e:terminal: all pass (a first run had one tabs failure, which passed alone and on a full rerun of the gate; the change does not touch tabs).

🤖 Generated with Claude Code

https://claude.ai/code/session_01FHHaWKR4M5QtW7Wecyuk4t

Maxaubert and others added 2 commits October 7, 2026 04:27
JSON with comments (.jsonc, tsconfig.json, .vscode/*.json and the other
well-known names) went to the strict JSON grammar and JSON.parse, so every
comment was plain text under a squiggle. They now get a tokenizer with the
JSON grammar's tags plus comment tags, brace folding, and a JSONC check that
blanks comments and trailing commas (offsets kept) before JSON.parse, so a
missing comma is still underlined. JSON5 colours the same with no linter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FHHaWKR4M5QtW7Wecyuk4t
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FHHaWKR4M5QtW7Wecyuk4t
@Maxaubert
Maxaubert merged commit e47658e into main Oct 7, 2026
3 checks passed
@Maxaubert
Maxaubert deleted the fix/312-jsonc-comments branch October 7, 2026 15:19
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.

JSONC: comments are underlined as errors and not coloured as comments

1 participant