aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/lsp_settings.vim13
-rw-r--r--test/lsp_settings.vimspec44
2 files changed, 46 insertions, 11 deletions
diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim
index 0b149f1..55d9452 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
@@ -401,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])
@@ -408,7 +409,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..36db445 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')
@@ -83,4 +83,38 @@ Describe lsp_settings
endtry
End
End
+
+ 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
+ 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
+ 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
+ exe 'augroup! ' . v
+ endfor
+ unlet g:lsp_settings
+ End
+ End
End