Repository navigation
fix(editor): JSONC comments read as comments, not errors (#312) - #314
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsmapped.jsoncand.json5to the strict@codemirror/lang-jsongrammar, and CodeView attachedjsonLinter(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, althoughcodeTheme.tsmapst.comment/t.lineComment/t.blockCommentto--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) pluslineComment/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:blankJsoncturns comments and trailing commas into spaces with every offset and line break kept, thenjsoncErrorsrunsJSON.parseon 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:lintfield 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.jsoninside a.vscodefolder (langFor(name, path))..json5colours the same with no linter (bare keys and single quotes would be false errors). Plain.jsonand.ipynbstay strict.CodeView.tsx:langFor(name, path)andlintFor(lang)replace the inline regex.Files
src/renderer/src/lib/jsoncMode.ts(new)src/renderer/src/lib/jsonc.test.ts(new, 13 tests)src/renderer/src/lib/codeLang.tssrc/renderer/src/lib/codeLint.tssrc/renderer/src/components/CodeView.tsxtools/e2e/run.mjs(jsoncscenario)CLAUDE.md(rule with the owner's words)package.json,package-lock.json(0.92.1 to 0.92.2)Gates
npm run typecheck: cleannpm run lint: 0 errors (7 existing warnings, none in changed files)npx vitest run: 171 files passed, 2539 tests passed (2 skipped)jsonce2e: 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.pnglooked at.npm run e2e:terminal: all pass (a first run had onetabsfailure, 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