From bc2e42cc6cab19bd17e1ef8604422e05c33009f3 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 31 Jan 2020 17:31:49 +0900 Subject: Should work with the user's wrong settings --- autoload/lsp_settings.vim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim index 0b149f1..07feb8b 100644 --- a/autoload/lsp_settings.vim +++ b/autoload/lsp_settings.vim @@ -352,11 +352,8 @@ function! s:vim_lsp_load_or_suggest(ft) abort if !empty(l:default) && l:default != l:server.command continue endif - let l:command = lsp_settings#get(l:server.command, 'cmd', l:server.command) - if type(l:command) == type([]) - let l:command = l:command[0] - endif - if !lsp_settings#executable(l:command) + let l:command = lsp_settings#get(l:server.command, 'cmd', []) + if empty(l:command) && !lsp_settings#executable(l:server.command) let l:script = printf('%s/%s.vim', s:checkers_dir, l:server.command) if !filereadable(l:script) || has_key(l:server, 'fallback') continue -- cgit v1.2.3-54-g00ecf From 6e645f09027a512a38454ae11716e5feb165f32e Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 31 Jan 2020 18:00:33 +0900 Subject: Add test --- autoload/lsp_settings.vim | 2 +- test/lsp_settings.vimspec | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim index 07feb8b..9762f6b 100644 --- a/autoload/lsp_settings.vim +++ b/autoload/lsp_settings.vim @@ -405,7 +405,7 @@ function! lsp_settings#init() abort endif exe 'augroup' lsp_settings#utils#group_name(l:ft) autocmd! - exe 'autocmd FileType' l:ft 'call s:vim_lsp_load_or_suggest(' string(l:ft) ')' + exe 'autocmd FileType' l:ft printf("call s:vim_lsp_load_or_suggest('%s')", l:ft) augroup END endfor augroup vim_lsp_suggest diff --git a/test/lsp_settings.vimspec b/test/lsp_settings.vimspec index 529187e..4af6de6 100644 --- a/test/lsp_settings.vimspec +++ b/test/lsp_settings.vimspec @@ -83,4 +83,16 @@ Describe lsp_settings endtry End End + + Describe lsp_settings#exec_path + It should setup commands and autocmds. + call lsp_settings#init() + autocmd vim_lsp_suggest_python + Assert exists(':LspInstallServer') + delcommand LspInstallServer + for v in map(filter(split(execute('autocmd'), '\n'), 'v:val=~"^vim_lsp_"'), 'split(v:val, " ")[0]') + exe 'autocmd!' v + endfor + End + End End -- cgit v1.2.3-54-g00ecf From df1ce0dbe106553165949d12c95e54d3c0447646 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 31 Jan 2020 18:04:46 +0900 Subject: Fix test --- test/lsp_settings.vimspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lsp_settings.vimspec b/test/lsp_settings.vimspec index 4af6de6..a03d4bd 100644 --- a/test/lsp_settings.vimspec +++ b/test/lsp_settings.vimspec @@ -84,7 +84,7 @@ Describe lsp_settings End End - Describe lsp_settings#exec_path + Describe lsp_settings#init It should setup commands and autocmds. call lsp_settings#init() autocmd vim_lsp_suggest_python -- cgit v1.2.3-54-g00ecf From c588857b64808afc660b721e12d78389ec57e205 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 31 Jan 2020 18:28:14 +0900 Subject: Add test --- autoload/lsp_settings.vim | 4 ++++ test/lsp_settings.vimspec | 34 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim index 9762f6b..55d9452 100644 --- a/autoload/lsp_settings.vim +++ b/autoload/lsp_settings.vim @@ -398,6 +398,10 @@ function! s:vim_lsp_load_or_suggest(ft) abort endif endfunction +function! lsp_settings#clear() abort + let s:ftmap = {} +endfunction + function! lsp_settings#init() abort for l:ft in keys(s:settings) if has_key(g:, 'lsp_settings_whitelist') && index(g:lsp_settings_whitelist, l:ft) == -1 || empty(s:settings[l:ft]) diff --git a/test/lsp_settings.vimspec b/test/lsp_settings.vimspec index a03d4bd..2485ca1 100644 --- a/test/lsp_settings.vimspec +++ b/test/lsp_settings.vimspec @@ -20,12 +20,12 @@ Describe lsp_settings Assert Equals(lsp_settings#executable('cmd'), 1) else Assert Equals(lsp_settings#executable('sh'), 1) - endif + endif Assert Equals(lsp_settings#executable('unknown-command'), 0) End It should return 0 when command is not in server/foo-bar/foo-bar - let l:servers_dir = lsp_settings#servers_dir() + let l:servers_dir = lsp_settings#servers_dir() try call delete(l:servers_dir . '/foo-bar', 'rf') @@ -37,7 +37,7 @@ Describe lsp_settings End It should return 1 when command is executable in server/foo-bar/foo-bar - let l:servers_dir = lsp_settings#servers_dir() + let l:servers_dir = lsp_settings#servers_dir() try call delete(l:servers_dir . '/foo-bar', 'rf') @@ -61,11 +61,11 @@ Describe lsp_settings Assert Equals(empty(lsp_settings#exec_path('cmd')), 0) else Assert Equals(empty(lsp_settings#exec_path('sh')), 0) - endif + endif End It should return 1 when command is executable in server/foo-bar/foo-bar - let l:servers_dir = lsp_settings#servers_dir() + let l:servers_dir = lsp_settings#servers_dir() try call delete(l:servers_dir . '/foo-bar', 'rf') @@ -86,12 +86,32 @@ Describe lsp_settings Describe lsp_settings#init It should setup commands and autocmds. + call lsp_settings#clear() call lsp_settings#init() autocmd vim_lsp_suggest_python Assert exists(':LspInstallServer') delcommand LspInstallServer - for v in map(filter(split(execute('autocmd'), '\n'), 'v:val=~"^vim_lsp_"'), 'split(v:val, " ")[0]') - exe 'autocmd!' v + Assert !exists('#vim_lsp_suggest_efm_langserver') + for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_"') + exe 'augroup ' . v + autocmd! + augroup END + exe 'augroup! ' . v + endfor + bw! + End + + It should setup commands and autocmds with python. + call lsp_settings#clear() + call lsp_settings#init() + new + Throw /E117/ :setfiletype python + bw! + for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_suggest"') + exe 'augroup ' . v + autocmd! + augroup END + exe 'augroup! ' . v endfor End End -- cgit v1.2.3-54-g00ecf From ba47b4e67fe42073c5178606774416cac15f9b06 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 31 Jan 2020 18:36:12 +0900 Subject: Add wrong configuration --- test/lsp_settings.vimspec | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/lsp_settings.vimspec b/test/lsp_settings.vimspec index 2485ca1..36db445 100644 --- a/test/lsp_settings.vimspec +++ b/test/lsp_settings.vimspec @@ -95,7 +95,7 @@ Describe lsp_settings for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_"') exe 'augroup ' . v autocmd! - augroup END + augroup END exe 'augroup! ' . v endfor bw! @@ -105,14 +105,16 @@ Describe lsp_settings call lsp_settings#clear() call lsp_settings#init() new + let g:lsp_settings = {'pyls': {'cmd': ['foo', 'bar']}} Throw /E117/ :setfiletype python bw! for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_suggest"') exe 'augroup ' . v autocmd! - augroup END + augroup END exe 'augroup! ' . v endfor + unlet g:lsp_settings End End End -- cgit v1.2.3-54-g00ecf