From 61892e8586a2f7ffe0c7399dc85effd73fbcf91b Mon Sep 17 00:00:00 2001 From: Peter Benjamin Date: Sat, 9 Sep 2023 15:28:38 -0700 Subject: 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 --- ale_linters/json/vscodejson.vim | 18 +++++++++++++++++- test/linter/test_json_vscodejson.vader | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/linter/test_json_vscodejson.vader 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 " Description: VSCode json language server +call ale#Set('json_vscodejson_executable', '') + +function! ale_linters#json#vscodejson#GetExecutable(buffer) abort + let l:executable = ale#Var(a:buffer, 'json_vscodejson_executable') + + if l:executable is# '' + 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'] -- cgit v1.2.3