-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Use proper JSONC grammar #7255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use proper JSONC grammar #7255
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
Important
The changes in this PR will not appear on GitHub until the next release has been made and deployed. See here for more details.
Turns out that GitHub (unlike VS Code's default theme) highlights the token "support.type" with a very similar shade of blue as the value tokens For that reason, I've added a formatting step in the syncing process to convert the scope "support.type" to "entity.name.tag" in order to get the same color as keys in JSON files. Just need to wait another 3 months and JSONC will finally look good! |
@DecimalTurn In the future, you might want to consult this file to judge the similarity between different scopes. In addition, this is worth a read if you're unfamiliar with how TextMate scopes differ to CSS classes. |
@Alhadis Thanks for sharing, very useful! |
VSCode does their own reformatting aswell https://github.com/microsoft/vscode/blob/main/extensions/json/build/update-grammars.js {
"key": "value"
} "key": "value" |
Yeah, but I'm using the final product, so this shouldn't be the reason for the discrepencies. And even with the 9.2.0 release, the problem with coloring wasn't fixed 😞. Could it be that PrettyLights gives precedence to the first token here? That would mean that the |
@Alhadis has a page/gist with how prettylights renders various parts of grammars but I can't remember its location. |
found it https://github.com/Alhadis/Atom-GitHubSyntax?tab=readme-ov-file#textmate-vs-css and heres the supported scopes https://github.com/Alhadis/language-etc/blob/master/samples/lists/scope-previews.nanorc does https://novalightshow.netlify.app/ correctly show Githubs shortfall? |
Ironically, this was already linked in this thread, but I evidently didn't read it properly as it clearly answers my previous question 😅.
Unfortunately, no. The behavior varies between the two. |
The space in that scope's name is ambiguous. Did you mean to tokenise code like this…? <token scope="string.json.comments">
<token scope="entity.name.tag.property-name.json.comments">
</token> Or this…? <token scope="string.json.comments entity.name.tag.property-name.json.comments"> (Both of the above code-blocks are using pseudocode to communicate the intended token structure). If it's the latter, and you really did mean to include a space in a scope-name, then it's malformed. Whitespace will be treated as-is by the TextMate engine, and will be matched only by a selector that specifies a scope that's literally named document.body.classList.toggle("comments entity");
// Uncaught DOMException: DOMTokenList.toggle: The token can not contain whitespace. The other problem is that TextMate selectors are order-sensitive, a matter that's discussed in detail here. Basically, By the same token (no pun intended), you can inhibit highlighting of desirable scopes that have undesirable appearances on GitHub; i.e, |
VSCode splits the scopeNames on spaces I don't know why VSCode chose to change it
VSCode is order sensitive just like TextMate |
Shit, I wasn't aware of that. It's been a while since I've even touched the editor, but I faintly recall CSS being used at some point… (which might've been a vague assumption based solely on VS Code being an Electron app, and therefore implemented with a CSS/HTML-based interface). I stand corrected regarding VSCode's TextMate implementation, then. |
@Alhadis, I can't really answer questions with regards to the original intentions because that grammar is mostly an exact copy of the grammar for JSONC used by VS Code internally (from here). My goal was to get the same behavior as what is seen in VS Code with as few changes as possible. To solve this latest tokenization isssue, I've changed the order to be : |
@DecimalTurn TextMate 2.0 doesn't like spaces in it scopeNames |
Really? This screenshot from Textmate produced with this version (that I just created to test this) shows that the |
@DecimalTurn I believe @RedCMD intended to write:
The space doesn't invalidate the entire scope-list, only those that come after it. The |
Ok, that was my understanding as well. Thanks for clarifying. |
Very interesting findings @RedCMD, thanks for sharing. This means that if PrettyLights behaves the same as TextMate, we should see that JSONC keys highlighted with purple if I follow the logic correctly. That's still better than blue, so I'm willing to let it as is just to test things out (for science!). |
Description
At the moment, the Javascript grammar is used for JSONC (JSON with comments). This is not ideal since it makes the keys have the same highlighting as strings making it less pleasant to read:
Looking at the official grammar used by VS Code, we get a nicer experience:
This PR changes the grammar to use the official VS Code grammar for JSONC. However, to avoid adding the whole VS Code repo as a submodule, I've used a "mirror" repo that remains synced with the official version.
Checklist: