You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copied from a draft issue on the WASM/Modern tree-sitter project.
This is an interesting idea because tree-sitter-json properly parses JavaScript-style comments. They aren't automatically errors, which means that tree-sitter-json could just as easily support a JSONC grammar (i.e., “JSON with comments,” used in the VS Code sense) as it does a JSON grammar.
Right now, inserting a comment into a JSON file (using its modern Tree-sitter grammar) has no effect; the comment is highlighted neither as a comment nor as an invalid token.
We could do the following:
Create another grammar called “JSONC” (or “JSON (with comments)” or something similar) that's nearly identical to the JSON grammar. They can share the same tree-sitter-json WASM files.
Both grammars should use the same existing highlights.scm, but each one should import its own highlights.scm that's unique from the other one:
The JSON grammar's unique SCM file would mark comment nodes as invalid.illegal.
The JSONC grammar's unique SCM file would mark comment nodes as comment.line or comment.block as appropriate.
Since some usages of JSON-with-comments seem to reuse the .json file extension, we could also add an “Allow comments in JSON files” setting to the language-json config schema. If that setting is enabled, the JSON grammar's behavior with comments would be reversed.
The text was updated successfully, but these errors were encountered:
There's another draft issue about adding a JSON5 grammar. That would take more effort, since some of JSON5's enhancements aren't understood by tree-sitter-json. There is a community JSON5 tree-sitter parser (though I haven't investigated it too deeply), but since it'd need a different parser, it might as well be a community package unless people clamor for it. (I think JSON5 is a good idea, but it's not exactly catching on in my corners of the development world.)
Copied from a draft issue on the WASM/Modern tree-sitter project.
This is an interesting idea because
tree-sitter-json
properly parses JavaScript-style comments. They aren't automatically errors, which means thattree-sitter-json
could just as easily support a JSONC grammar (i.e., “JSON with comments,” used in the VS Code sense) as it does a JSON grammar.Right now, inserting a comment into a JSON file (using its modern Tree-sitter grammar) has no effect; the comment is highlighted neither as a comment nor as an invalid token.
We could do the following:
tree-sitter-json
WASM files.highlights.scm
, but each one should import its ownhighlights.scm
that's unique from the other one:comment
nodes asinvalid.illegal
.comment
nodes ascomment.line
orcomment.block
as appropriate..json
file extension, we could also add an “Allow comments in JSON files” setting to thelanguage-json
config schema. If that setting is enabled, the JSON grammar's behavior with comments would be reversed.The text was updated successfully, but these errors were encountered: