Skip to content

Commit

Permalink
vscode-json-languageserver support (dense-analysis#4164)
Browse files Browse the repository at this point in the history
* vscode-json-languageserver-bin support

VSCode JSON languageserver has schema support for linting and
completions.

I have enabled snippets support (`snippetSupport`) even if it is not
fully supported. `label` that comes with completions response can be
used as well.

* Test fix.

* vscode-json-languageserver instead of vscode-json-languageserver-bin

vscode-json-languageserver is more up-to-date (about 1 year old),
vscode-json-languageserver-bin is 4 years old.

* Use git root.

* Documentation update.

* Trying to sort ordering issue.

* One more attempt

* One more attempt

* Uppercase seems to win.

* Clean-up

* Clean-up 2

* Test removed.
  • Loading branch information
daliusd authored and cyyever committed Jul 11, 2022
1 parent 9786e2d commit e4c7d0f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
16 changes: 16 additions & 0 deletions ale_linters/json/vscodejson.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
" Author: Dalius Dobravolskas <dalius.dobravolskas@gmail.com>
" Description: VSCode json languageserver

function! ale_linters#json#vscodejson#GetProjectRoot(buffer) abort
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')

return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : ''
endfunction

call ale#linter#Define('json', {
\ 'name': 'vscodejson',
\ 'lsp': 'stdio',
\ 'executable': 'vscode-json-languageserver',
\ 'command': '%e --stdio',
\ 'project_root': function('ale_linters#json#vscodejson#GetProjectRoot'),
\})
2 changes: 1 addition & 1 deletion autoload/ale/linter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let s:default_ale_linters = {
\ 'hack': ['hack'],
\ 'help': [],
\ 'inko': ['inko'],
\ 'json': ['jsonlint', 'spectral'],
\ 'json': ['jsonlint', 'spectral', 'vscodejson'],
\ 'json5': [],
\ 'jsonc': [],
\ 'perl': ['perlcritic'],
Expand Down
12 changes: 12 additions & 0 deletions doc/ale-json.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ g:ale_json_spectral_use_global *g:ale_json_spectral_use_global*

See |ale-integrations-local-executables|

===============================================================================
vscodejson *ale-json-vscode*

Website: https://www.npmjs.com/package/vscode-json-languageserver

Installation
-------------------------------------------------------------------------------

Install VSCode json language server either globally or locally: >
npm install -g vscode-json-languageserver
<

===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Notes:
* `tsserver`
* `xo`
* JSON
* `VSCode JSON language server`
* `cspell`
* `dprint`
* `eslint`
Expand Down
2 changes: 2 additions & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ g:ale_linters *g:ale_linters*
\ 'help': [],
\ 'inko': ['inko'],
\ 'json': ['jsonlint', 'spectral'],
\ 'json': ['jsonlint', 'spectral', 'vscodejson'],
\ 'json5': [],
\ 'jsonc': [],
\ 'perl': ['perlcritic'],
Expand Down Expand Up @@ -2961,6 +2962,7 @@ documented in additional help files.
jq....................................|ale-json-jq|
prettier..............................|ale-json-prettier|
spectral..............................|ale-json-spectral|
vscodejson............................|ale-json-vscode|
jsonc...................................|ale-jsonc-options|
eslint................................|ale-jsonc-eslint|
jsonnet.................................|ale-jsonnet-options|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ formatting.
* [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29)
* [xo](https://github.com/sindresorhus/xo)
* JSON
* [VSCode JSON language server](https://www.npmjs.com/package/vscode-json-languageserver)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell) :warning:
* [dprint](https://dprint.dev)
* [eslint](http://eslint.org/) :warning:
Expand Down
2 changes: 1 addition & 1 deletion test/test_filetype_linter_defaults.vader
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Execute(The defaults for the inko filetype should be correct):
AssertEqual [], GetLinterNames('inko')

Execute(The defaults for the json filetype should be correct):
AssertEqual ['jsonlint', 'spectral'], GetLinterNames('json')
AssertEqual ['jsonlint', 'spectral', 'vscodejson'], GetLinterNames('json')

let g:ale_linters_explicit = 1

Expand Down

0 comments on commit e4c7d0f

Please sign in to comment.