aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/lsp_settings.vim19
-rw-r--r--plugin/lsp_settings.vim34
2 files changed, 50 insertions, 3 deletions
diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim
index e8419a8..536d993 100644
--- a/autoload/lsp_settings.vim
+++ b/autoload/lsp_settings.vim
@@ -100,7 +100,24 @@ function! lsp_settings#autocd(server_info) abort
endif
endfunction
-function! lsp_settings#complete_installer(arglead, cmdline, cursorpos) abort
+function! lsp_settings#complete_uninstall(arglead, cmdline, cursorpos) abort
+ let l:settings = json_decode(join(readfile(s:root_dir . '/settings.json'), "\n"))
+ call remove(l:settings, '$schema')
+
+ let l:servers_dir = get(g:, 'lsp_settings_servers_dir', s:servers_dir)
+ let l:installers = []
+ for l:ft in keys(l:settings)
+ for l:conf in l:settings[l:ft]
+ if !isdirectory(l:servers_dir . '/' . l:conf.command)
+ continue
+ endif
+ call add(l:installers, l:conf.command)
+ endfor
+ endfor
+ return filter(l:installers, 'stridx(v:val, a:arglead) == 0')
+endfunction
+
+function! lsp_settings#complete_install(arglead, cmdline, cursorpos) abort
let l:settings = json_decode(join(readfile(s:root_dir . '/settings.json'), "\n"))
call remove(l:settings, '$schema')
diff --git a/plugin/lsp_settings.vim b/plugin/lsp_settings.vim
index 569e28d..8d33b08 100644
--- a/plugin/lsp_settings.vim
+++ b/plugin/lsp_settings.vim
@@ -85,6 +85,30 @@ function! s:vim_lsp_installer(ft, ...) abort
return []
endfunction
+function! s:error(msg) abort
+ echohl Error
+ echomsg a:msg
+ echohl None
+endfunction
+
+function! s:valid_name(name) abort
+ return a:name =~# '^[a-zA-Z0-9_-]\+$'
+endfunction
+
+function! s:vim_lsp_uninstall_server(name) abort
+ if !s:valid_name(a:name)
+ call s:error('invalid server name')
+ return
+ endif
+ let l:servers_dir = get(g:, 'lsp_settings_servers_dir', s:servers_dir)
+ let l:server_install_dir = l:servers_dir . '/' . a:name
+ if !isdirectory(l:server_install_dir)
+ call s:error('server not found')
+ return
+ endif
+ call delete(l:server_install_dir, 'rf')
+endfunction
+
" neovim passes third argument as 'exit' while vim passes only 2 arguments
function! s:vim_lsp_install_server_post(command, job, code, ...) abort
if a:code != 0
@@ -106,8 +130,13 @@ function! s:vim_lsp_install_server_post(command, job, code, ...) abort
endfunction
function! s:vim_lsp_install_server(ft, name) abort
+ if !s:valid_name(a:name)
+ call s:error('invalid server name')
+ return
+ endif
let l:entry = s:vim_lsp_installer(a:ft, a:name)
if empty(l:entry)
+ call s:error('server not found')
return
endif
let l:servers_dir = get(g:, 'lsp_settings_servers_dir', s:servers_dir)
@@ -137,7 +166,7 @@ function! s:vim_lsp_settings_suggest(ft) abort
echohl Directory
echomsg 'Please do :LspInstallServer to enable Language Server'
echohl None
- command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_installer LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
+ command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_install LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
endif
endfunction
@@ -171,6 +200,7 @@ function! s:vim_lsp_settings() abort
autocmd!
autocmd BufNewFile,BufRead * call s:vim_lsp_suggest_plugin()
augroup END
+ command! -nargs=? -complete=customlist,lsp_settings#complete_uninstall LspUninstallServer call s:vim_lsp_uninstall_server(<q-args>)
endfunction
function! s:vim_lsp_suggest_plugin() abort
@@ -259,7 +289,7 @@ function! s:vim_lsp_load_or_suggest(ft) abort
else
doautocmd User lsp_setup
if exists(':LspInstallServer') !=# 2
- command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_installer LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
+ command! -nargs=? -buffer -complete=customlist,lsp_settings#complete_install LspInstallServer call s:vim_lsp_install_server(&l:filetype, <q-args>)
endif
endif