diff options
| author | William Boman <william@redwill.se> | 2021-10-26 09:47:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 09:47:20 +0200 |
| commit | c7ef12d8f99490c984ec171c7341577513b435a8 (patch) | |
| tree | aea6fa17846dbc45c832fa28da1025ef03861d31 /plugin/nvim-lsp-installer.vim | |
| parent | mac's not fun (diff) | |
| download | mason-c7ef12d8f99490c984ec171c7341577513b435a8.tar mason-c7ef12d8f99490c984ec171c7341577513b435a8.tar.gz mason-c7ef12d8f99490c984ec171c7341577513b435a8.tar.bz2 mason-c7ef12d8f99490c984ec171c7341577513b435a8.tar.lz mason-c7ef12d8f99490c984ec171c7341577513b435a8.tar.xz mason-c7ef12d8f99490c984ec171c7341577513b435a8.tar.zst mason-c7ef12d8f99490c984ec171c7341577513b435a8.zip | |
add synchronous variants of commands for better headless interop (#189)
Diffstat (limited to 'plugin/nvim-lsp-installer.vim')
| -rw-r--r-- | plugin/nvim-lsp-installer.vim | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/plugin/nvim-lsp-installer.vim b/plugin/nvim-lsp-installer.vim index 6ee00af8..fc815e72 100644 --- a/plugin/nvim-lsp-installer.vim +++ b/plugin/nvim-lsp-installer.vim @@ -4,6 +4,8 @@ let g:loaded_nvim_lsp_installer = v:true let s:save_cpo = &cpo set cpo&vim +let s:no_confirm_flag = "--no-confirm" + function! s:LspInstallCompletion(...) abort return join(sort(luaeval("require'nvim-lsp-installer.servers'.get_available_server_names()")), "\n") endfunction @@ -12,20 +14,41 @@ function! s:LspUninstallCompletion(...) abort return join(sort(luaeval("require'nvim-lsp-installer.servers'.get_installed_server_names()")), "\n") endfunction -function! s:LspInstall(server_names) abort - for server_name in split(a:server_names, " ") - call luaeval("require'nvim-lsp-installer'.install(_A)", server_name) - endfor +function! s:LspUninstallAllCompletion(...) abort + return s:no_confirm_flag +endfunction + +function! s:ParseArgs(args) + let sync = a:args[0] == "--sync" + let servers = sync ? a:args[1:] : a:args + return { 'sync': sync, 'servers': servers } +endfunction + +function! s:LspInstall(args) abort + let parsed_args = s:ParseArgs(a:args) + if parsed_args.sync + call luaeval("require'nvim-lsp-installer'.install_sync(_A)", parsed_args.servers) + else + for server_name in l:parsed_args.servers + call luaeval("require'nvim-lsp-installer'.install(_A)", server_name) + endfor + endif endfunction -function! s:LspUninstall(server_names) abort - for server_name in split(a:server_names, " ") - call luaeval("require'nvim-lsp-installer'.uninstall(_A)", server_name) - endfor +function! s:LspUninstall(args) abort + let parsed_args = s:ParseArgs(a:args) + if parsed_args.sync + call luaeval("require'nvim-lsp-installer'.uninstall_sync(_A)", parsed_args.servers) + else + for server_name in l:parsed_args.servers + call luaeval("require'nvim-lsp-installer'.uninstall(_A)", server_name) + endfor + endif endfunction -function! s:LspUninstallAll() abort - lua require'nvim-lsp-installer'.uninstall_all() +function! s:LspUninstallAll(args) abort + let no_confirm = get(a:args, 0, "") == s:no_confirm_flag + call luaeval("require'nvim-lsp-installer'.uninstall_all(_A)", no_confirm ? v:true : v:false) endfunction function! s:LspPrintInstalled() abort @@ -40,10 +63,10 @@ function! s:LspInstallLog() abort exe 'tabnew ' .. luaeval("require'nvim-lsp-installer.log'.outfile") endfunction -command! -nargs=+ -complete=custom,s:LspInstallCompletion LspInstall exe s:LspInstall("<args>") -command! -nargs=+ -complete=custom,s:LspUninstallCompletion LspUninstall exe s:LspUninstall("<args>") +command! -bar -nargs=+ -complete=custom,s:LspInstallCompletion LspInstall call s:LspInstall([<f-args>]) +command! -bar -nargs=+ -complete=custom,s:LspUninstallCompletion LspUninstall call s:LspUninstall([<f-args>]) +command! -bar -nargs=? -complete=custom,s:LspUninstallAllCompletion LspUninstallAll call s:LspUninstallAll([<f-args>]) -command! LspUninstallAll call s:LspUninstallAll() command! LspPrintInstalled call s:LspPrintInstalled() command! LspInstallInfo call s:LspInstallInfo() command! LspInstallLog call s:LspInstallLog() |
