Skip to content

Commit 8af4f8e

Browse files
committed
Add jsonc, closes #635
1 parent e566860 commit 8af4f8e

File tree

7 files changed

+82
-1
lines changed

7 files changed

+82
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A collection of language packs for Vim.
77
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
88
99
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
10-
- It **installs and updates 120+ times faster** than the <!--Package Count-->600<!--/Package Count--> packages it consists of.
10+
- It **installs and updates 120+ times faster** than the <!--Package Count-->601<!--/Package Count--> packages it consists of.
1111
- It is also more secure (scripts loaded for every filetype are generated by vim-polyglot)
1212
- Best syntax and indentation support (no other features). Hand-selected language packs.
1313
- Automatically detects indentation (includes performance-optimized version of [vim-sleuth](https://github.com/tpope/vim-sleuth), can be disabled)
@@ -111,6 +111,7 @@ On top of all language packs from [vim repository](https://github.com/vim/vim/tr
111111
- [jq](https://github.com/vito-c/jq.vim) (JSONiq syntax highlighting for jq files)
112112
- [json5](https://github.com/GutenYe/json5.vim) (JSON5 syntax highlighting for json5 files)
113113
- [json](https://github.com/elzr/vim-json) (JSON syntax highlighting for json, avsc, geojson, gltf, har and 13 more files)
114+
- [jsonc](https://github.com/neoclide/jsonc.vim) (Syntax highlighting for cjson and jsonc files)
114115
- [jsonnet](https://github.com/google/vim-jsonnet) (Jsonnet syntax highlighting for jsonnet and libsonnet files)
115116
- [jst](https://github.com/briancollins/vim-jst) (EJS syntax highlighting for ejs, ect and jst files)
116117
- [jsx](https://github.com/MaxMEllon/vim-jsx-pretty) (JSX syntax highlighting for jsx files)

autoload/polyglot/sleuth.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ let s:globs = {
263263
\ 'jq': '*.jq,.jqrc,.jqrc*',
264264
\ 'json': '*.json,*.avsc,*.geojson,*.gltf,*.har,*.ice,*.JSON-tmLanguage,*.jsonl,*.mcmeta,*.tfstate,*.tfstate.backup,*.topojson,*.webapp,*.webmanifest,*.yy,*.yyp,*.jsonp,*.template,.arcconfig,.htmlhintrc,.tern-config,.tern-project,.watchmanconfig,composer.lock,mcmod.info,Pipfile.lock',
265265
\ 'json5': '*.json5',
266+
\ 'jsonc': '*.cjson,*.jsonc,coc-settings.json,.eslintrc.json,.babelrc,.jshintrc,.jslintrc,.mocharc.json,coffeelint.json,tsconfig.json,jsconfig.json',
266267
\ 'jsonnet': '*.jsonnet,*.libsonnet',
267268
\ 'jsp': '*.jsp',
268269
\ 'jst': '*.ejs,*.ect,*.jst',

ftdetect/polyglot.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ set cpo&vim
142142

143143
" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE
144144

145+
if !has_key(g:polyglot_is_disabled, 'jsonc')
146+
au BufNewFile,BufRead *.cjson,*.jsonc,{.,}babelrc,{.,}eslintrc.json,{.,}jshintrc,{.,}jslintrc,{.,}mocharc.json,coc-settings.json,coffeelint.json,jsconfig.json,tsconfig.json setf jsonc
147+
endif
148+
145149
if !has_key(g:polyglot_is_disabled, 'mint')
146150
au BufNewFile,BufRead *.mint setf mint
147151
endif

indent/jsonc.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if has_key(g:polyglot_is_disabled, 'jsonc')
2+
finish
3+
endif
4+
5+
runtime! indent/json.vim

packages.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5554,3 +5554,11 @@ filetypes:
55545554
patterns:
55555555
- pattern: '*.mint'
55565556
description: Mint (https://www.mint-lang.com/)
5557+
---
5558+
name: jsonc
5559+
remote: neoclide/jsonc.vim
5560+
filetypes:
5561+
- name: jsonc
5562+
patterns:
5563+
- pattern: '*.cjson,coc-settings.json,*.jsonc,.eslintrc.json,.babelrc,.jshintrc,.jslintrc,.mocharc.json,coffeelint.json,tsconfig.json,jsconfig.json'
5564+
description: 'JSON with comments (https://komkom.github.io/)'

syntax/jsonc.vim

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
if has_key(g:polyglot_is_disabled, 'jsonc')
2+
finish
3+
endif
4+
5+
" Syntax setup {{{1
6+
if exists('b:current_syntax') && b:current_syntax == 'jsonc'
7+
finish
8+
endif
9+
10+
" Syntax: Strings {{{1
11+
syn region jsoncString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsoncEscape
12+
syn region jsoncString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=jsoncEscape
13+
14+
" Syntax: JSON Keywords {{{1
15+
" Separated into a match and region because a region by itself is always greedy
16+
syn match jsoncKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword
17+
18+
" Syntax: Escape sequences
19+
syn match jsoncEscape "\\["\\/bfnrt]" contained
20+
syn match jsoncEscape "\\u\x\{4}" contained
21+
22+
" Syntax: Numbers {{{1
23+
syn match jsoncNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
24+
syn keyword jsoncNumber Infinity -Infinity
25+
26+
" Syntax: An integer part of 0 followed by other digits is not allowed.
27+
syn match jsoncNumError "-\=\<0\d\.\d*\>"
28+
29+
" Syntax: Boolean {{{1
30+
syn keyword jsoncBoolean true false
31+
32+
" Syntax: Null {{{1
33+
syn keyword jsoncNull null
34+
35+
" Syntax: Braces {{{1
36+
syn match jsoncBraces "[{}\[\]]"
37+
syn match jsoncObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/
38+
39+
" Syntax: Comment {{{1
40+
syn region jsoncLineComment start=+\/\/+ end=+$+ keepend
41+
syn region jsoncLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold
42+
syn region jsoncComment start="/\*" end="\*/" fold
43+
44+
" Define the default highlighting. {{{1
45+
hi def link jsoncString String
46+
hi def link jsoncObjAssign Identifier
47+
hi def link jsoncEscape Special
48+
hi def link jsoncNumber Number
49+
hi def link jsoncBraces Operator
50+
hi def link jsoncNull Function
51+
hi def link jsoncBoolean Boolean
52+
hi def link jsoncLineComment Comment
53+
hi def link jsoncComment Comment
54+
hi def link jsoncNumError Error
55+
hi def link jsoncKeywordMatch Label
56+
57+
if !exists('b:current_syntax')
58+
let b:current_syntax = 'jsonc'
59+
endif
60+
61+
" vim: fdm=marker

tests/filetypes.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ call TestFiletype('xpm')
645645
call TestFiletype('xpm2')
646646
call TestFiletype('context')
647647
call TestFiletype('mint')
648+
call TestFiletype('jsonc')
648649

649650
" DO NOT EDIT CODE ABOVE, IT IS GENERATED WITH MAKEFILE
650651

0 commit comments

Comments
 (0)