├── .gitignore ├── CONTRIBUTING ├── LICENSE ├── README.md ├── autoload └── jsonnet.vim ├── doc └── vim-jsonnet.txt ├── ftdetect └── jsonnet.vim ├── ftplugin └── jsonnet.vim ├── jsonnet-screenshot.png ├── plugin └── jsonnet.vim ├── syntax └── jsonnet.vim └── syntax_checkers └── jsonnet └── jsonnet.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.swp 3 | doc/tags 4 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Before we can merge your pull request, we need you to sign either the Google individual or corporate 2 | contributor license agreement (CLA), unless you are a Google employee, intern, or contractor. 3 | 4 | Please see http://google.github.io/jsonnet/doc/contributing.html for more information. 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-jsonnet 2 | 3 | [Jsonnet][jsonnet] filetype plugin for Vim. 4 | 5 | [jsonnet]: http://jsonnet.org 6 | 7 | ![A screenshot of Jsonnet syntax highlighting](https://raw.githubusercontent.com/google/vim-jsonnet/master/jsonnet-screenshot.png) 8 | 9 | # Install 10 | 11 | To install via Vim plugin managers: 12 | 13 | ### Vundle 14 | 15 | ```viml 16 | Plugin 'google/vim-jsonnet' 17 | ``` 18 | 19 | ### vim-plug 20 | 21 | ```viml 22 | Plug 'google/vim-jsonnet' 23 | ``` 24 | 25 | ### dein.vim 26 | 27 | ```viml 28 | call dein#add('google/vim-jsonnet') 29 | ``` 30 | 31 | ### Pathogen 32 | 33 | ```sh 34 | git clone https://github.com/google/vim-jsonnet ~/.vim/bundle/vim-jsonnet 35 | ``` 36 | 37 | ### Neovim with no Package Manager 38 | 39 | ```sh 40 | mkdir ~/.local/share/nvim/site/pack/plugins/start 41 | cd ~/.local/share/nvim/site/pack/plugins/start 42 | git clone https://github.com/google/vim-jsonnet 43 | ``` 44 | 45 | ## More Info 46 | 47 | For more info on Jsonnet: 48 | * Jsonnet Website: http://jsonnet.org 49 | * Jsonnet Repository: https://github.com/google/jsonnet 50 | -------------------------------------------------------------------------------- /autoload/jsonnet.vim: -------------------------------------------------------------------------------- 1 | 2 | 3 | " Options. 4 | 5 | if !exists("g:jsonnet_command") 6 | let g:jsonnet_command = "jsonnet" 7 | endif 8 | 9 | if !exists("g:jsonnet_fmt_command") 10 | let g:jsonnet_fmt_command = "jsonnetfmt" 11 | endif 12 | 13 | if !exists('g:jsonnet_fmt_options') 14 | let g:jsonnet_fmt_options = '' 15 | endif 16 | 17 | if !exists('g:jsonnet_fmt_fail_silently') 18 | let g:jsonnet_fmt_fail_silently = 1 19 | endif 20 | 21 | 22 | " System runs a shell command. It will reset the shell to /bin/sh for Unix-like 23 | " systems if it is executable. 24 | function! jsonnet#System(str, ...) 25 | let l:shell = &shell 26 | if executable('/bin/sh') 27 | let &shell = '/bin/sh' 28 | endif 29 | 30 | try 31 | let l:output = call("system", [a:str] + a:000) 32 | return l:output 33 | finally 34 | let &shell = l:shell 35 | endtry 36 | endfunction 37 | 38 | 39 | " CheckBinPath checks whether the given binary exists or not and returns the 40 | " path of the binary. It returns an empty string if it doesn't exists. 41 | function! jsonnet#CheckBinPath(binName) 42 | 43 | if executable(a:binName) 44 | if exists('*exepath') 45 | let binPath = exepath(a:binName) 46 | return binPath 47 | else 48 | return a:binName 49 | endif 50 | else 51 | echo "vim-jsonnet: could not find '" . a:binName . "'." 52 | return "" 53 | endif 54 | 55 | endfunction 56 | 57 | " Format calls `jsonnetfmt ... ` on the file and replaces the file with the 58 | " auto formatted version. Does some primitive error checking of the 59 | " jsonnetfmt command too. 60 | function! jsonnet#Format() 61 | 62 | " Save cursor position and many other things. 63 | let l:curw = winsaveview() 64 | 65 | " Write current unsaved buffer to a temp file 66 | let l:tmpname = tempname() 67 | call writefile(getline(1, '$'), l:tmpname) 68 | 69 | " get the command first so we can test it 70 | let l:binName = g:jsonnet_fmt_command 71 | 72 | " check if the user has installed command binary. 73 | let l:binPath = jsonnet#CheckBinPath(l:binName) 74 | if empty(l:binPath) 75 | return 76 | endif 77 | 78 | 79 | " Populate the final command. 80 | let l:command = l:binPath 81 | " The inplace modification is default. Makes file management easier 82 | let l:command = l:command . ' -i ' 83 | let l:command = l:command . g:jsonnet_fmt_options 84 | 85 | " Execute the compiled jsonnetfmt command and save the return value 86 | let l:out = jsonnet#System(l:command . " " . l:tmpname) 87 | let l:errorCode = v:shell_error 88 | 89 | if l:errorCode == 0 90 | " The format command succeeded Move the formatted temp file over the 91 | " current file and restore other settings 92 | 93 | " stop undo recording 94 | try | silent undojoin | catch | endtry 95 | 96 | let l:originalFileFormat = &fileformat 97 | if exists("*getfperm") 98 | " save old file permissions 99 | let l:originalFPerm = getfperm(expand('%')) 100 | endif 101 | " Overwrite current file with the formatted temp file 102 | call rename(l:tmpname, expand('%')) 103 | 104 | if exists("*setfperm") && l:originalFPerm != '' 105 | call setfperm(expand('%'), l:originalFPerm) 106 | endif 107 | " the file has been changed outside of vim, enable reedit 108 | mkview 109 | silent edit! 110 | let &fileformat = l:originalFileFormat 111 | let &syntax = &syntax 112 | silent loadview 113 | elseif g:jsonnet_fmt_fail_silently == 0 114 | " FixMe: We could leverage the errors coming from the `jsonnetfmt` and 115 | " give immediate feedback to the user at every save time. 116 | " Our inspiration, vim-go, opens a new list below the current edit 117 | " window and shows the errors (the output of the fmt command). 118 | " We are not sure whether this is desired in the vim-jsonnet community 119 | " or not. Nevertheless, this else block is a suitable place to benefit 120 | " from the `jsonnetfmt` errors. 121 | endif 122 | 123 | " Restore our cursor/windows positions. 124 | call winrestview(l:curw) 125 | endfunction 126 | 127 | function! jsonnet#GetVisualSelection() 128 | " Source: https://stackoverflow.com/a/6271254 129 | " Why is this not a built-in Vim script function?! 130 | let [line_start, column_start] = getpos("'<")[1:2] 131 | let [line_end, column_end] = getpos("'>")[1:2] 132 | let lines = getline(line_start, line_end) 133 | if len(lines) == 0 134 | return '' 135 | endif 136 | let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)] 137 | let lines[0] = lines[0][column_start - 1:] 138 | return join(lines, "\n") 139 | endfun 140 | 141 | " Format calls `jsonnetfmt ... ` on a Visual selection 142 | function! jsonnet#FormatVisual() 143 | " Get current visual selection 144 | let l:selection = jsonnet#GetVisualSelection() 145 | 146 | " Get the command first so we can test it 147 | let l:binName = g:jsonnet_fmt_command 148 | 149 | " Check if the user has installed command binary. 150 | let l:binPath = jsonnet#CheckBinPath(l:binName) 151 | if empty(l:binPath) 152 | return 153 | endif 154 | 155 | " Populate the final command. 156 | let l:command = l:binPath 157 | let l:command = l:command . ' -e ' 158 | let l:command = l:command . g:jsonnet_fmt_options 159 | 160 | " Execute the compiled jsonnetfmt command and save the return value 161 | let l:out = jsonnet#System(l:command . " \"" . l:selection . "\"") 162 | let l:errorCode = v:shell_error 163 | 164 | " Save register contents 165 | let reg = '"' 166 | let save_cb = &cb 167 | let regInfo = getreginfo(reg) 168 | try 169 | " Set register to formatted output 170 | call setreg(reg,l:out) 171 | " Paste formatted output 172 | silent exe 'norm! gv'.(reg == '"' ? '' : '"' . reg).'p`[' 173 | finally 174 | " Restore register contents 175 | let &cb = save_cb 176 | call setreg(reg, regInfo) 177 | endtry 178 | endfunction 179 | 180 | " Evaluate jsonnet into vsplit 181 | function! jsonnet#Eval() 182 | let output = system(g:jsonnet_command . ' ' . shellescape(expand('%'))) 183 | vnew 184 | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile ft=jsonnet 185 | put! = output 186 | endfunction 187 | -------------------------------------------------------------------------------- /doc/vim-jsonnet.txt: -------------------------------------------------------------------------------- 1 | *vim-jsonnet.txt* Jsonnet development plugin 2 | *vim-jsonnet* 3 | 4 | ==================================================================================== 5 | # # ### # # # ##### ####### # # # # ####### ####### 6 | # # # ## ## # # # # # ## # ## # # # 7 | # # # # # # # # # # # # # # # # # # # 8 | # # # # # # ##### # ##### # # # # # # # # ##### # 9 | # # # # # # # # # # # # # # # # # # 10 | # # # # # # # # # # # # ## # ## # # 11 | # ### # # ##### ##### ####### # # # # ####### # 12 | ==================================================================================== 13 | CONTENTS *jsonnet-contents* 14 | 15 | 1. Intro........................................|jsonnet-intro| 16 | 2. Install......................................|jsonnet-install| 17 | 3. Commands.....................................|jsonnet-commands| 18 | 4. Mappings.....................................|jsonnet-mappings| 19 | 6. Functions....................................|jsonnet-functions| 20 | 7. Settings.....................................|jsonnet-settings| 21 | 8. Troubleshooting..............................|jsonnet-troubleshooting| 22 | 9. Credits......................................|jsonnet-credits| 23 | 24 | ============================================================================== 25 | INTRO *jsonnet-intro* 26 | 27 | ============================================================================== 28 | INSTALL *jsonnet-install* 29 | 30 | ============================================================================== 31 | COMMANDS *jsonnet-commands* 32 | 33 | *:JsonnetFmt* 34 | :JsonnetFmt 35 | 36 | Filter the current Jsonnet buffer through `jsonnetfmt`. It tries to 37 | preserve cursor position and avoids replacing the buffer with stderr 38 | output. 39 | 40 | ============================================================================== 41 | MAPPINGS *jsonnet-mappings* 42 | 43 | ============================================================================== 44 | FUNCTIONS *jsonnet-functions* 45 | 46 | *jsonnet#Format()* 47 | 48 | Filter the current Jsonnet buffer through `jsonnetfmt`. It tries to 49 | preserve cursor position and avoids replacing the buffer with stderr 50 | output. 51 | 52 | ============================================================================== 53 | SETTINGS *jsonnet-settings* 54 | 55 | *'g:jsonnet_fmt_on_save'* 56 | 57 | Use this option to auto |:JsonnetFmt| on save. By default it's enabled > 58 | 59 | let g:jsonnet_fmt_on_save = 1 60 | < 61 | *'g:jsonnet_command'* 62 | 63 | Use this option to define which tool is used to format. By default `jsonnet` is 64 | used > 65 | 66 | let g:jsonnet_command = "jsonnet" 67 | < 68 | *'g:jsonnet_fmt_command'* 69 | 70 | Use this option to define which parameter is used with *g:jsonnet_command* tool. 71 | By default `fmt` is used > 72 | 73 | let g:jsonnet_fmt_command = "fmt" 74 | < 75 | *'g:jsonnet_fmt_options'* 76 | 77 | Use this option to add additional options to the 78 | |'g:jsonnet_command'| + |'g:jsonnet_fmt_command'|. Default is empty. > 79 | 80 | let g:jsonnet_fmt_options = '' 81 | < 82 | *'g:jsonnet_fmt_fail_silently'* 83 | 84 | Use this option to enable processing of 85 | |'g:jsonnet_command'| + |'g:jsonnet_fmt_command'| command if it fails. By default 86 | it is turned off. By default the error output from the 87 | |'g:jsonnet_command'| + |'g:jsonnet_fmt_command'| command is ignored. 88 | FixMe: The processing of the |'g:jsonnet_command'| + |'g:jsonnet_fmt_command'| 89 | is not implemented yet. So clearing this option would not do anything at this time. > 90 | 91 | let g:jsonnet_fmt_fail_silently = 1 92 | < 93 | 94 | ============================================================================== 95 | TROUBLESHOOTING *jsonnet-troubleshooting* 96 | 97 | ============================================================================== 98 | CREDITS *jsonnet-credits* 99 | 100 | 101 | -------------------------------------------------------------------------------- /ftdetect/jsonnet.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2014 Google Inc. All rights reserved. 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " http://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | autocmd BufNewFile,BufRead *.jsonnet setf jsonnet 16 | autocmd BufNewFile,BufRead *.libsonnet setf jsonnet 17 | -------------------------------------------------------------------------------- /ftplugin/jsonnet.vim: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | " -- fmt 5 | command! -nargs=0 JsonnetFmt call jsonnet#Format() 6 | 7 | " -- eval 8 | command! -nargs=0 JsonnetEval call jsonnet#Eval() 9 | 10 | setlocal commentstring=//\ %s 11 | 12 | 13 | -------------------------------------------------------------------------------- /jsonnet-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vim-jsonnet/4ebc6619ddce5d032a985b42a9864154c3d20e4a/jsonnet-screenshot.png -------------------------------------------------------------------------------- /plugin/jsonnet.vim: -------------------------------------------------------------------------------- 1 | 2 | 3 | " A plugin for jsonnet files. 4 | " Install useful tools for *.jsonnet and *.libsonnet files 5 | 6 | if exists('g:loaded_jsonnet') 7 | finish 8 | endif 9 | let g:loaded_jsonnet = 1 10 | 11 | function! s:fmtAutosave() 12 | " Jsonnet code formatting on save 13 | if get(g:, "jsonnet_fmt_on_save", 1) 14 | call jsonnet#Format() 15 | endif 16 | endfunction 17 | 18 | 19 | " auto group and clear inside prevents multiple registration of the same 20 | " auto commands 21 | augroup vim-jsonnet 22 | autocmd! 23 | autocmd BufReadPre *.jsonnet setlocal foldmethod=syntax 24 | autocmd BufReadPre *.libsonnet setlocal foldmethod=syntax 25 | autocmd BufReadPre *.jsonnet setlocal foldlevel=100 26 | autocmd BufReadPre *.libsonnet setlocal foldlevel=100 27 | autocmd BufWritePre *.jsonnet call s:fmtAutosave() 28 | autocmd BufWritePre *.libsonnet call s:fmtAutosave() 29 | augroup END 30 | 31 | command! -range JsonnetFmtVis call jsonnet#FormatVisual() 32 | -------------------------------------------------------------------------------- /syntax/jsonnet.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2014 Google Inc. All rights reserved. 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " http://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | syntax match Number "\<\d*\([Ee][+-]\?\d\+\)\?\>" 16 | syntax match Number "\<\d\+[.]\d*\([Ee][+-]\?\d\+\)\?\>" 17 | syntax match Number "\<[.]\d\+\([Ee][+-]\?\d\+\)\?\>" 18 | 19 | " std library (builtin and std.jsonnet) 20 | " Generated with: 21 | " PROG='std.lines(["syn match Constant \"std.%s\"" % fn for fn in std.objectFieldsAll(std) if fn[0] >= "a" && fn[0] <= "z"])'' 22 | " go run github.com/google/go-jsonnet/cmd/jsonnet@v0.19.1 --string - <<<"${PROG}" 23 | syn match Constant "std.abs" 24 | syn match Constant "std.acos" 25 | syn match Constant "std.all" 26 | syn match Constant "std.any" 27 | syn match Constant "std.asciiLower" 28 | syn match Constant "std.asciiUpper" 29 | syn match Constant "std.asin" 30 | syn match Constant "std.assertEqual" 31 | syn match Constant "std.atan" 32 | syn match Constant "std.base64" 33 | syn match Constant "std.base64Decode" 34 | syn match Constant "std.base64DecodeBytes" 35 | syn match Constant "std.ceil" 36 | syn match Constant "std.char" 37 | syn match Constant "std.clamp" 38 | syn match Constant "std.codepoint" 39 | syn match Constant "std.cos" 40 | syn match Constant "std.count" 41 | syn match Constant "std.decodeUTF8" 42 | syn match Constant "std.deepJoin" 43 | syn match Constant "std.encodeUTF8" 44 | syn match Constant "std.endsWith" 45 | syn match Constant "std.equals" 46 | syn match Constant "std.escapeStringBash" 47 | syn match Constant "std.escapeStringDollars" 48 | syn match Constant "std.escapeStringJson" 49 | syn match Constant "std.escapeStringPython" 50 | syn match Constant "std.exp" 51 | syn match Constant "std.exponent" 52 | syn match Constant "std.extVar" 53 | syn match Constant "std.filter" 54 | syn match Constant "std.filterMap" 55 | syn match Constant "std.find" 56 | syn match Constant "std.findSubstr" 57 | syn match Constant "std.flatMap" 58 | syn match Constant "std.flattenArrays" 59 | syn match Constant "std.floor" 60 | syn match Constant "std.foldl" 61 | syn match Constant "std.foldr" 62 | syn match Constant "std.format" 63 | syn match Constant "std.get" 64 | syn match Constant "std.id" 65 | syn match Constant "std.isArray" 66 | syn match Constant "std.isBoolean" 67 | syn match Constant "std.isFunction" 68 | syn match Constant "std.isNumber" 69 | syn match Constant "std.isObject" 70 | syn match Constant "std.isString" 71 | syn match Constant "std.join" 72 | syn match Constant "std.length" 73 | syn match Constant "std.lines" 74 | syn match Constant "std.log" 75 | syn match Constant "std.lstripChars" 76 | syn match Constant "std.makeArray" 77 | syn match Constant "std.manifestIni" 78 | syn match Constant "std.manifestJson" 79 | syn match Constant "std.manifestJsonEx" 80 | syn match Constant "std.manifestJsonMinified" 81 | syn match Constant "std.manifestPython" 82 | syn match Constant "std.manifestPythonVars" 83 | syn match Constant "std.manifestToml" 84 | syn match Constant "std.manifestTomlEx" 85 | syn match Constant "std.manifestXmlJsonml" 86 | syn match Constant "std.manifestYamlDoc" 87 | syn match Constant "std.manifestYamlStream" 88 | syn match Constant "std.mantissa" 89 | syn match Constant "std.map" 90 | syn match Constant "std.mapWithIndex" 91 | syn match Constant "std.mapWithKey" 92 | syn match Constant "std.max" 93 | syn match Constant "std.md5" 94 | syn match Constant "std.member" 95 | syn match Constant "std.mergePatch" 96 | syn match Constant "std.min" 97 | syn match Constant "std.mod" 98 | syn match Constant "std.modulo" 99 | syn match Constant "std.native" 100 | syn match Constant "std.objectFields" 101 | syn match Constant "std.objectFieldsAll" 102 | syn match Constant "std.objectFieldsEx" 103 | syn match Constant "std.objectHas" 104 | syn match Constant "std.objectHasAll" 105 | syn match Constant "std.objectHasEx" 106 | syn match Constant "std.objectValues" 107 | syn match Constant "std.objectValuesAll" 108 | syn match Constant "std.parseHex" 109 | syn match Constant "std.parseInt" 110 | syn match Constant "std.parseJson" 111 | syn match Constant "std.parseOctal" 112 | syn match Constant "std.parseYaml" 113 | syn match Constant "std.pow" 114 | syn match Constant "std.primitiveEquals" 115 | syn match Constant "std.prune" 116 | syn match Constant "std.range" 117 | syn match Constant "std.repeat" 118 | syn match Constant "std.resolvePath" 119 | syn match Constant "std.reverse" 120 | syn match Constant "std.rstripChars" 121 | syn match Constant "std.set" 122 | syn match Constant "std.setDiff" 123 | syn match Constant "std.setInter" 124 | syn match Constant "std.setMember" 125 | syn match Constant "std.setUnion" 126 | syn match Constant "std.sign" 127 | syn match Constant "std.sin" 128 | syn match Constant "std.slice" 129 | syn match Constant "std.sort" 130 | syn match Constant "std.split" 131 | syn match Constant "std.splitLimit" 132 | syn match Constant "std.splitLimitR" 133 | syn match Constant "std.sqrt" 134 | syn match Constant "std.startsWith" 135 | syn match Constant "std.strReplace" 136 | syn match Constant "std.stringChars" 137 | syn match Constant "std.stripChars" 138 | syn match Constant "std.substr" 139 | syn match Constant "std.tan" 140 | syn match Constant "std.thisFile" 141 | syn match Constant "std.toString" 142 | syn match Constant "std.trace" 143 | syn match Constant "std.type" 144 | syn match Constant "std.uniq" 145 | 146 | syn match Type "\$" 147 | 148 | syn region String start='L\="' skip='\\\\\|\\"' end='"' 149 | syn region String start='L\=\'' skip='\\\\\|\\\'' end='\'' 150 | syn region String start='|||\s*\n\+\z(\s*\)' end='^\z1\@!\s*|||' 151 | 152 | " Highlight python style string formatting. 153 | syn match Special "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=String 154 | syn match Special "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=String 155 | 156 | syn region Comment start="/[*]" end="[*]/" contains=@Spell 157 | syn match Comment "//.*$" contains=@Spell 158 | syn match Comment "#.*$" contains=@Spell 159 | 160 | syn match Keyword "\<[a-zA-Z_][a-z0-9A-Z_]*\s*\(([^)]*)\)\?\s*+\?::\?:\?" 161 | 162 | syn region Object start="{" end="}" fold transparent 163 | syn region Object start="(" end=")" fold transparent 164 | syn region Object start="=" end=";" fold transparent 165 | 166 | syntax keyword Include import importstr importbin 167 | syntax keyword Type function self super 168 | syntax keyword Statement assert if then else for in 169 | syntax keyword Special local tailstrict 170 | syntax keyword Constant true false null 171 | syntax keyword Underlined error 172 | 173 | 174 | -------------------------------------------------------------------------------- /syntax_checkers/jsonnet/jsonnet.vim: -------------------------------------------------------------------------------- 1 | " Vim syntastic plugin 2 | " Language: jsonnet 3 | " Author: Benjamin Staffin 4 | " 5 | " For details on how to add an external Syntastic checker: 6 | " https://github.com/scrooloose/syntastic/wiki/Syntax-Checker-Guide#external 7 | 8 | if exists("g:loaded_syntastic_jsonnet_jsonnet_checker") 9 | finish 10 | endif 11 | let g:loaded_syntastic_jsonnet_jsonnet_checker = 1 12 | 13 | let s:save_cpo = &cpo 14 | set cpo&vim 15 | 16 | function! SyntaxCheckers_jsonnet_jsonnet_IsAvailable() dict 17 | return executable(self.getExec()) 18 | endfunction 19 | 20 | function! SyntaxCheckers_jsonnet_jsonnet_GetLocList() dict 21 | 22 | let errorformat = 23 | \ 'STATIC ERROR:\ %f:%l:%c:%m,' . 24 | \ 'STATIC ERROR:\ %f:%l:%c-%\d%#:%m,' . 25 | \ '%ERUNTIME ERROR:\ %m,' . 26 | \ '%C\ %#%f:(%\?%l:%c)%\?%.%#' 27 | 28 | return SyntasticMake({ 29 | \ 'makeprg': self.makeprgBuild({}), 30 | \ 'errorformat': errorformat }) 31 | endfunction 32 | 33 | call g:SyntasticRegistry.CreateAndRegisterChecker({ 34 | \ 'filetype': 'jsonnet', 35 | \ 'name': 'jsonnet'}) 36 | 37 | " Register for syntastic tab completion: 38 | if exists('g:syntastic_extra_filetypes') 39 | call add(g:syntastic_extra_filetypes, 'jsonnet') 40 | else 41 | let g:syntastic_extra_filetypes = ['jsonnet'] 42 | endif 43 | 44 | let &cpo = s:save_cpo 45 | unlet s:save_cpo 46 | --------------------------------------------------------------------------------