Skip to content

Commit

Permalink
Add jsonc, closes #635
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Dec 30, 2020
1 parent e566860 commit 8af4f8e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A collection of language packs for Vim.
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
- It **installs and updates 120+ times faster** than the <!--Package Count-->600<!--/Package Count--> packages it consists of.
- It **installs and updates 120+ times faster** than the <!--Package Count-->601<!--/Package Count--> packages it consists of.
- It is also more secure (scripts loaded for every filetype are generated by vim-polyglot)
- Best syntax and indentation support (no other features). Hand-selected language packs.
- Automatically detects indentation (includes performance-optimized version of [vim-sleuth](https://github.com/tpope/vim-sleuth), can be disabled)
Expand Down Expand Up @@ -111,6 +111,7 @@ On top of all language packs from [vim repository](https://github.com/vim/vim/tr
- [jq](https://github.com/vito-c/jq.vim) (JSONiq syntax highlighting for jq files)
- [json5](https://github.com/GutenYe/json5.vim) (JSON5 syntax highlighting for json5 files)
- [json](https://github.com/elzr/vim-json) (JSON syntax highlighting for json, avsc, geojson, gltf, har and 13 more files)
- [jsonc](https://github.com/neoclide/jsonc.vim) (Syntax highlighting for cjson and jsonc files)
- [jsonnet](https://github.com/google/vim-jsonnet) (Jsonnet syntax highlighting for jsonnet and libsonnet files)
- [jst](https://github.com/briancollins/vim-jst) (EJS syntax highlighting for ejs, ect and jst files)
- [jsx](https://github.com/MaxMEllon/vim-jsx-pretty) (JSX syntax highlighting for jsx files)
Expand Down
1 change: 1 addition & 0 deletions autoload/polyglot/sleuth.vim
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ let s:globs = {
\ 'jq': '*.jq,.jqrc,.jqrc*',
\ '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',
\ 'json5': '*.json5',
\ 'jsonc': '*.cjson,*.jsonc,coc-settings.json,.eslintrc.json,.babelrc,.jshintrc,.jslintrc,.mocharc.json,coffeelint.json,tsconfig.json,jsconfig.json',
\ 'jsonnet': '*.jsonnet,*.libsonnet',
\ 'jsp': '*.jsp',
\ 'jst': '*.ejs,*.ect,*.jst',
Expand Down
4 changes: 4 additions & 0 deletions ftdetect/polyglot.vim
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ set cpo&vim

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

if !has_key(g:polyglot_is_disabled, 'jsonc')
au BufNewFile,BufRead *.cjson,*.jsonc,{.,}babelrc,{.,}eslintrc.json,{.,}jshintrc,{.,}jslintrc,{.,}mocharc.json,coc-settings.json,coffeelint.json,jsconfig.json,tsconfig.json setf jsonc
endif

if !has_key(g:polyglot_is_disabled, 'mint')
au BufNewFile,BufRead *.mint setf mint
endif
Expand Down
5 changes: 5 additions & 0 deletions indent/jsonc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if has_key(g:polyglot_is_disabled, 'jsonc')
finish
endif

runtime! indent/json.vim
8 changes: 8 additions & 0 deletions packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5554,3 +5554,11 @@ filetypes:
patterns:
- pattern: '*.mint'
description: Mint (https://www.mint-lang.com/)
---
name: jsonc
remote: neoclide/jsonc.vim
filetypes:
- name: jsonc
patterns:
- pattern: '*.cjson,coc-settings.json,*.jsonc,.eslintrc.json,.babelrc,.jshintrc,.jslintrc,.mocharc.json,coffeelint.json,tsconfig.json,jsconfig.json'
description: 'JSON with comments (https://komkom.github.io/)'
61 changes: 61 additions & 0 deletions syntax/jsonc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
if has_key(g:polyglot_is_disabled, 'jsonc')
finish
endif

" Syntax setup {{{1
if exists('b:current_syntax') && b:current_syntax == 'jsonc'
finish
endif

" Syntax: Strings {{{1
syn region jsoncString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsoncEscape
syn region jsoncString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=jsoncEscape

" Syntax: JSON Keywords {{{1
" Separated into a match and region because a region by itself is always greedy
syn match jsoncKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword

" Syntax: Escape sequences
syn match jsoncEscape "\\["\\/bfnrt]" contained
syn match jsoncEscape "\\u\x\{4}" contained

" Syntax: Numbers {{{1
syn match jsoncNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
syn keyword jsoncNumber Infinity -Infinity

" Syntax: An integer part of 0 followed by other digits is not allowed.
syn match jsoncNumError "-\=\<0\d\.\d*\>"

" Syntax: Boolean {{{1
syn keyword jsoncBoolean true false

" Syntax: Null {{{1
syn keyword jsoncNull null

" Syntax: Braces {{{1
syn match jsoncBraces "[{}\[\]]"
syn match jsoncObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/

" Syntax: Comment {{{1
syn region jsoncLineComment start=+\/\/+ end=+$+ keepend
syn region jsoncLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold
syn region jsoncComment start="/\*" end="\*/" fold

" Define the default highlighting. {{{1
hi def link jsoncString String
hi def link jsoncObjAssign Identifier
hi def link jsoncEscape Special
hi def link jsoncNumber Number
hi def link jsoncBraces Operator
hi def link jsoncNull Function
hi def link jsoncBoolean Boolean
hi def link jsoncLineComment Comment
hi def link jsoncComment Comment
hi def link jsoncNumError Error
hi def link jsoncKeywordMatch Label

if !exists('b:current_syntax')
let b:current_syntax = 'jsonc'
endif

" vim: fdm=marker
1 change: 1 addition & 0 deletions tests/filetypes.vim
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ call TestFiletype('xpm')
call TestFiletype('xpm2')
call TestFiletype('context')
call TestFiletype('mint')
call TestFiletype('jsonc')

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

Expand Down

0 comments on commit 8af4f8e

Please sign in to comment.