even comments in JSON aren't allowed, there are more and more cases where comments in JSON are accepted, e.g. TypeScript, Visual Studio Code, etc.
This patch adds the config parameter g:vim_json_allow_comments=1 to highlight comments as comments instead of error.
Note: highlighting of /* */ comments don't work properly; i hope somebody with more knowledge on syntax highlighting might help out...
https://github.com/vim/vim/pull/6400
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Merging #6400 into master will decrease coverage by
0.01%.
The diff coverage isn/a.
@@ Coverage Diff @@ ## master #6400 +/- ## ========================================== - Coverage 88.02% 88.00% -0.02% ========================================== Files 144 144 Lines 159143 159143 ========================================== - Hits 140084 140054 -30 - Misses 19059 19089 +30
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/ui.c | 79.83% <0.00%> (-3.82%) |
⬇️ |
| src/gui.c | 62.92% <0.00%> (-0.71%) |
⬇️ |
| src/os_unix.c | 70.66% <0.00%> (-0.23%) |
⬇️ |
| src/if_xcmdsrv.c | 88.73% <0.00%> (-0.18%) |
⬇️ |
| src/sign.c | 94.77% <0.00%> (-0.18%) |
⬇️ |
| src/gui_gtk_x11.c | 58.57% <0.00%> (-0.15%) |
⬇️ |
| src/ex_getln.c | 91.84% <0.00%> (ø) |
|
| src/search.c | 91.46% <0.00%> (+0.10%) |
⬆️ |
| src/netbeans.c | 76.37% <0.00%> (+0.29%) |
⬆️ |
| src/testing.c | 93.64% <0.00%> (+0.57%) |
⬆️ |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 0ad3e89...6162da6. Read the comment docs.
Have you contacted the maintainer?
Comments are not allowed in json. This is non-standard. There is really no need to add yet another option. I can't even think of a program that supports them OTOH.
If you really need the comments, just add the following to your after/syntax/json.vim:
hi link jsonCommentError Comment
The whole point of highlight-default is to use the default value only if it hasn't been linked yet. This is from :help :highlight-default:
Using [default] is especially useful to overrule the highlighting of a
specific syntax file. For example, the C syntax file contains: >
:highlight default link cComment Comment
If you like Question highlighting for C comments, put this in your vimrc file: >
:highlight link cComment Question
For the /* */ comments just take a look at the runtime/syntax/java.vim, javascript.vim, or c.vim files. They all use the same type of comments.
thank you for the hints, i will look at them later tonight.
typescript compiler generates tsconfig.json with comments, and the questions on how to make it work has been asked here: https://stackoverflow.com/questions/55669954/why-does-vim-highlight-all-my-json-comments-in-red
"json with comments is not json".
You can find plenty of references to this.
Perhaps we can use a different filetype for this? It's Javascript without the script.
Throwing in my 2p, as I has this debate with myself recently.
Increasingly, json is being used (for better or worse) as a human writable configuration format. The author of JSON famously said[see citation] that JSON doesn't contain comments (after all, it's an interchange format), but that if it were used as a configuration file format, then it makes perfect sense to use comments, and that implementations should run it through some sort of "minifier" before parsing.
All in all, JSON (the interchange format) certainly does not contain comments, but files-containing-a-single-JSON-object (let's call them .json files) legitimately can (and do).
citation:
My reference for this was this: http://web.archive.org/web/20100629021329/http://blog.getify.com/2010/06/json-comments/ (sadly the link to the source is dead, so it may not be reliable). Indeed I use json.minify for this purpose.
Summary of the quote:
A JSON encoder MUST NOT output comments. A JSON decoder MAY accept and ignore comments.
To add a bit of context, elzr/vim-json#61 is a long-standing open PR to add support for g:vim_json_comments. I forked it as kevinoid/vim-jsonc for the jsonc filetype and have incorporated a few fixes. Unfortunately, I've also found some significant implementation issues which I haven't had time to fix (e.g. kevinoid/vim-jsonc#1).
I'd be willing to fix the issues and help upstream the changes into elzr/vim-json or vim/vim if it is likely to be accepted.
I can't even think of a program that supports them OTOH.
It's not uncommon in the Node.js world. See https://github.com/kevinoid/vim-jsonc/blob/master/ftdetect/jsonc.vim for a list of recognizable filenames I've come across. (Along with manifest.json for WebExtensions which supports // but not /* */ comments.)
Perhaps we can use a different filetype for this?
I agree. Using a different filetype has the advantage of being easy to set via modelines and easy for users to understand and use. I'd suggest jsonc (obviously) but I've seen cjson used, and am not opposed to something more explicit like jsonwithcomments.
I'm not against jsonc, unless it's ambiguous. It seems to be known: https://filext.com/file-extension/JSONC
cjson has much fewer matches, and the first one refers to a Vim plugin :-)
closing this for #8450 (which just has been merged)
Closed #6400.
@chrisbra Thanks for tidying up the issues, but I'm not sure how #8450 (setting ft=json for JSON Patch) is related to this (supporting comments in JSON)?
(Other than that me commenting on both back-to-back, since I came across this issue when searching for JSON issues before opening that one. 😉 Sorry for the confusion.)
ah, okay. Sorry for the confusion. Will re-open then.
Reopened #6400.
I think this can be closed. Users who need comments in their json, can set the filetype to jsonc. There's already a syntax and filetype file in runtime for that.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
agree, thank you :-)
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Closed #6400.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()