Open savetheclocktower opened 1 week ago
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.