diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim index 75da49db..448ad0bf 100644 --- a/autoload/lsp_settings.vim +++ b/autoload/lsp_settings.vim @@ -223,6 +223,35 @@ function! lsp_settings#get(name, key, default) abort endfunction function! lsp_settings#exec_path(cmd) abort + + if get(g:, 'lsp_settings_use_install_file', 0) == 1 + let l:exec_path = lsp_settings#find_from_install_dir(a:cmd) + if l:exec_path != '' + return l:exec_path + endif + endif + + let l:exec_path = lsp_settings#find_from_path(a:cmd) + if l:exec_path != '' + return l:exec_path + endif + + let l:exec_path = lsp_settings#find_from_extra_path(a:cmd) + if l:exec_path != '' + return l:exec_path + endif + + if get(g:, 'lsp_settings_use_install_file', 0) == 0 + let l:exec_path = lsp_settings#find_from_install_dir(a:cmd) + if l:exec_path != '' + return l:exec_path + endif + endif + + return '' +endfunction + +function! lsp_settings#find_from_path(cmd) abort let l:paths = [] if has('win32') for l:path in split($PATH, ';') @@ -249,16 +278,32 @@ function! lsp_settings#exec_path(cmd) abort endif endfor endif + return '' +endfunction +function! lsp_settings#find_from_extra_path(cmd) abort let l:paths = get(g:, 'lsp_settings_extra_paths', '') if type(l:paths) == type([]) let l:paths = join(l:paths, ',') . ',' endif if !has('win32') - let l:paths .= lsp_settings#servers_dir() . '/' . a:cmd return lsp_settings#utils#first_one(globpath(l:paths, a:cmd, 1)) endif - let l:paths .= lsp_settings#servers_dir() . '\' . a:cmd + for l:ext in ['.exe', '.cmd', '.bat'] + let l:path = globpath(l:paths, a:cmd . l:ext, 1) + if !empty(l:path) + return lsp_settings#utils#first_one(l:path) + endif + endfor + return '' +endfunction + +function! lsp_settings#find_from_install_dir(cmd) abort + if !has('win32') + let l:paths = lsp_settings#servers_dir() . '/' . a:cmd + return lsp_settings#utils#first_one(globpath(l:paths, a:cmd, 1)) + endif + let l:paths = lsp_settings#servers_dir() . '\' . a:cmd for l:ext in ['.exe', '.cmd', '.bat'] let l:path = globpath(l:paths, a:cmd . l:ext, 1) if !empty(l:path) diff --git a/doc/vim-lsp-settings.txt b/doc/vim-lsp-settings.txt index afe448f9..30db60f5 100644 --- a/doc/vim-lsp-settings.txt +++ b/doc/vim-lsp-settings.txt @@ -172,6 +172,13 @@ g:lsp_settings_filetype_xxx one element and type of the element is |function|, vim-lsp-settings call it and the result is evaluated lazy. + *g:lsp_settings_use_install_file* +g:lsp_settings_use_install_file + Default: 0 + Set 0 Look for the executable file in the PATH environment variable and + execute it first if found. + Set 1 vim-lsp-settings installed executable if available + :LspSettingsLocalEdit [root] *:LspSettingsLocalEdit* Edit local settings. Accepts an optional explicit [root] directory that contains the .vim-lsp-settings config directory.