summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Benjamin <petermbenjamin@gmail.com>2023-09-09 15:28:38 -0700
committerGitHub <noreply@github.com>2023-09-09 23:28:38 +0100
commit61892e8586a2f7ffe0c7399dc85effd73fbcf91b (patch)
tree9f6533262e7d7f63fb57321f50090d35c4bf14b4
parent92267a14ba4ef4f96ea5822366f5b24231b1d9d7 (diff)
downloadale-61892e8586a2f7ffe0c7399dc85effd73fbcf91b.zip
fix(json): update vscode json lsp name (#4601)
* fix(json): update vscode json lsp name * fix(vscodejson): fallback to previous name Co-authored-by: w0rp <devw0rp@gmail.com>
-rw-r--r--ale_linters/json/vscodejson.vim18
-rw-r--r--test/linter/test_json_vscodejson.vader33
2 files changed, 50 insertions, 1 deletions
diff --git a/ale_linters/json/vscodejson.vim b/ale_linters/json/vscodejson.vim
index dcaee010..be9eaf53 100644
--- a/ale_linters/json/vscodejson.vim
+++ b/ale_linters/json/vscodejson.vim
@@ -1,6 +1,22 @@
" Author: Dalius Dobravolskas <dalius.dobravolskas@gmail.com>
" Description: VSCode json language server
+call ale#Set('json_vscodejson_executable', '<auto>')
+
+function! ale_linters#json#vscodejson#GetExecutable(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'json_vscodejson_executable')
+
+ if l:executable is# '<auto>'
+ if ale#engine#IsExecutable(a:buffer, 'vscode-json-languageserver')
+ let l:executable = 'vscode-json-languageserver'
+ else
+ let l:executable = 'vscode-json-language-server'
+ endif
+ endif
+
+ return l:executable
+endfunction
+
function! ale_linters#json#vscodejson#GetProjectRoot(buffer) abort
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
@@ -10,7 +26,7 @@ endfunction
call ale#linter#Define('json', {
\ 'name': 'vscodejson',
\ 'lsp': 'stdio',
-\ 'executable': 'vscode-json-language-server',
+\ 'executable': function('ale_linters#json#vscodejson#GetExecutable'),
\ 'command': '%e --stdio',
\ 'project_root': function('ale_linters#json#vscodejson#GetProjectRoot'),
\})
diff --git a/test/linter/test_json_vscodejson.vader b/test/linter/test_json_vscodejson.vader
new file mode 100644
index 00000000..f627bb3d
--- /dev/null
+++ b/test/linter/test_json_vscodejson.vader
@@ -0,0 +1,33 @@
+Before:
+ let g:executable_map = {}
+
+ call ale#assert#SetUpLinterTest('json', 'vscodejson')
+
+ runtime autoload/ale/engine.vim
+
+ " Stub out IsExecutable so we can emulate it.
+ function! ale#engine#IsExecutable(buffer, executable) abort
+ return get(g:executable_map, a:executable)
+ endfunction
+
+After:
+ unlet! g:executable_map
+
+ call ale#assert#TearDownLinterTest()
+
+ runtime autoload/ale/engine.vim
+
+Execute(The default executable name should be correct):
+ let g:executable_map = {'vscode-json-languageserver': 1}
+
+ AssertLinter 'vscode-json-languageserver', [ale#Escape('vscode-json-languageserver') . ' --stdio']
+
+Execute(We should fall back on the old executable name):
+ let g:executable_map = {'vscode-json-languageserver': 0}
+
+ AssertLinter 'vscode-json-language-server', [ale#Escape('vscode-json-language-server') . ' --stdio']
+
+Execute(Executable name should be configurable):
+ let b:ale_json_vscodejson_executable = 'foo'
+
+ AssertLinter 'foo', [ale#Escape('foo') . ' --stdio']