aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2019-12-15 22:10:27 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2019-12-15 22:10:27 +0900
commit799457522c9aee6b126d95eb2fbc1a66286f664e (patch)
treeeda8dc1aadcc8126ffc939682728ac426e181a07
parentd93ca7e89884bc5f8656a60460e5f743810a2cb3 (diff)
downloadvim-lsp-settings-799457522c9aee6b126d95eb2fbc1a66286f664e.tar.gz
vim-lsp-settings-799457522c9aee6b126d95eb2fbc1a66286f664e.tar.bz2
vim-lsp-settings-799457522c9aee6b126d95eb2fbc1a66286f664e.zip
Add lsp_settings_extra_paths
-rw-r--r--autoload/lsp_settings.vim34
-rw-r--r--plugin/lsp_setup.vim32
-rw-r--r--setting/clangd.vim2
-rw-r--r--setting/gopls.vim2
-rw-r--r--setting/intelephense-server.vim2
-rw-r--r--setting/pyls.vim2
-rw-r--r--setting/rls.vim2
-rw-r--r--setting/solargraph.vim2
-rw-r--r--setting/typescript-language-server.vim2
-rw-r--r--setting/vim-language-server.vim2
10 files changed, 65 insertions, 17 deletions
diff --git a/autoload/lsp_settings.vim b/autoload/lsp_settings.vim
index e3ce81b..4d66b7f 100644
--- a/autoload/lsp_settings.vim
+++ b/autoload/lsp_settings.vim
@@ -1,11 +1,39 @@
function! lsp_settings#get(name, key, default) abort
- let l:config = get(g:, 'lsp_settings', {})
+ let l:config = get(g:, 'lsp_settings_extra_paths', {})
if !has_key(l:config, a:name)
- return a:default
+ if !has_key(l:config, '*')
+ return a:default
+ endif
+ let l:config = l:config['*']
+ else
+ let l:config = l:config[a:name]
endif
- let l:config = l:config[a:name]
if !has_key(l:config, a:key)
return a:default
endif
return l:config[a:key]
endfunction
+
+function! lsp_settings#exec_path(cmd) abort
+ if executable(a:cmd)
+ return a:cmd
+ endif
+ let l:paths = get(g:, 'lsp_settings_paths', '')
+ if !has('win32')
+ return !empty(globpath(l:paths, a:cmd))
+ endif
+ let l:path = globpath(l:paths, a:cmd . '.exe')
+ if !empty(l:path)
+ return l:path
+ endif
+ let l:path = globpath(l:paths, a:cmd . '.cmd')
+ if !empty(l:path)
+ return l:path
+ endif
+ let l:path = globpath(l:paths, a:cmd . '.bat')
+ if !empty(l:path)
+ return l:path
+ endif
+ return ''
+endfunction
+
diff --git a/plugin/lsp_setup.vim b/plugin/lsp_setup.vim
index 59c6fcb..ded904c 100644
--- a/plugin/lsp_setup.vim
+++ b/plugin/lsp_setup.vim
@@ -2,7 +2,27 @@ let s:setting_dir = expand('<sfile>:h:h').'/setting'
let s:installer_dir = expand('<sfile>:h:h').'/installer'
let s:setting = json_decode(join(readfile(expand('<sfile>:h:h').'/setting.json'), "\n"))
-function! s:vimlsp_installer()
+function! s:executable(cmd) abort
+ if executable(a:cmd)
+ return a:cmd
+ endif
+ let l:paths = get(g:, 'lsp_settings_extra_paths', '')
+ if !has('win32')
+ return !empty(globpath(l:paths, a:cmd))
+ endif
+ if !empty(globpath(l:paths, a:cmd . '.exe'))
+ return 1
+ endif
+ if !empty(globpath(l:paths, a:cmd . '.cmd'))
+ return 1
+ endif
+ if !empty(globpath(l:paths, a:cmd . '.bat'))
+ return 1
+ endif
+ return 0
+endfunction
+
+function! s:vimlsp_installer() abort
let l:setting = s:setting[&filetype]
if empty(l:setting)
return ''
@@ -11,12 +31,12 @@ function! s:vimlsp_installer()
for l:conf in l:setting
let l:missing = 0
for l:require in l:conf.requires
- if !executable(l:require)
+ if !s:executable(l:require)
let l:missing = 1
break
endif
endfor
- if l:missing == 0
+ if l:missing ==# 0
let l:found = l:conf
break
endif
@@ -30,7 +50,7 @@ function! s:vimlsp_installer()
else
let l:command = l:command . '.sh'
endif
- if !executable(l:command)
+ if !s:executable(l:command)
return ''
endif
return l:command
@@ -56,13 +76,13 @@ function! s:vimlsp_setting() abort
continue
endif
for l:server in s:setting[l:ft]
- if executable(l:server.command)
+ if s:executable(l:server.command)
exe 'source' printf('%s/%s.vim', s:setting_dir, l:server.command)
let l:found += 1
break
endif
endfor
- if l:found == 0
+ if l:found ==# 0
exe printf('augroup vimlsp_suggest_%s', l:ft)
au!
exe printf('autocmd FileType %s call s:vimlsp_settings_suggest()', l:ft)
diff --git a/setting/clangd.vim b/setting/clangd.vim
index f130b34..4c9ba11 100644
--- a/setting/clangd.vim
+++ b/setting/clangd.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_clangd
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'clangd',
- \ 'cmd': lsp_settings#get('clangd', 'cmd', {server_info->['clangd']}),
+ \ 'cmd': lsp_settings#get('clangd', 'cmd', {server_info->[lsp_settings#exec_path('clangd')]}),
\ 'initialization_options': lsp_settings#get('clangd', 'initialization_options', v:null),
\ 'whitelist': lsp_settings#get('clangd', 'whitelist', ['c', 'cpp', 'objc', 'objcpp']),
\ 'blacklist': lsp_settings#get('clangd', 'blacklist', []),
diff --git a/setting/gopls.vim b/setting/gopls.vim
index 1ed5cef..c5fcc88 100644
--- a/setting/gopls.vim
+++ b/setting/gopls.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_gopls
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'gopls',
- \ 'cmd': lsp_settings#get('gopls', 'cmd', {server_info->['gopls']}),
+ \ 'cmd': lsp_settings#get('gopls', 'cmd', {server_info->[lsp_settings#exec_path('gopls')]}),
\ 'initialization_options': lsp_settings#get('gopls', 'initialization_options', {"diagnostics": "true"}),
\ 'whitelist': lsp_settings#get('gopls', 'whitelist', ['go']),
\ 'blacklist': lsp_settings#get('gopls', 'blacklist', []),
diff --git a/setting/intelephense-server.vim b/setting/intelephense-server.vim
index 25f4ccf..ef10860 100644
--- a/setting/intelephense-server.vim
+++ b/setting/intelephense-server.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_intelephense_server
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'intelephense',
- \ 'cmd': lsp_settings#get('intelephense', 'cmd', {server_info->[&shell, &shellcmdflag, 'intelephense-server --stdio']}),
+ \ 'cmd': lsp_settings#get('intelephense', 'cmd', {server_info->[lsp_settings#exec_path('intelephense-server'), '--stdio']}),
\ 'whitelist': lsp_settings#get('intelephense', 'whitelist', ['php']),
\ 'blacklist': lsp_settings#get('intelephense', 'blacklist', []),
\ 'config': lsp_settings#get('intelephense', 'config', {}),
diff --git a/setting/pyls.vim b/setting/pyls.vim
index 686353e..177a429 100644
--- a/setting/pyls.vim
+++ b/setting/pyls.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_pyls
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'pyls',
- \ 'cmd': lsp_settings#get('pyls', 'cmd', {server_info->['pyls']}),
+ \ 'cmd': lsp_settings#get('pyls', 'cmd', {server_info->[lsp_settings#exec_path('pyls')]}),
\ 'initialization_options': lsp_settings#get('pyls', 'initialization_options', v:null),
\ 'whitelist': lsp_settings#get('pyls', 'whitelist', ['python']),
\ 'blacklist': lsp_settings#get('pyls', 'blacklist', []),
diff --git a/setting/rls.vim b/setting/rls.vim
index 252c658..4267795 100644
--- a/setting/rls.vim
+++ b/setting/rls.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_rls
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'rls',
- \ 'cmd': lsp_settings#get('rls', 'cmd', {server_info->['rls']}),
+ \ 'cmd': lsp_settings#get('rls', 'cmd', {server_info->[lsp_settings#exec_path('rls')]}),
\ 'initialization_options': lsp_settings#get('rls', 'initialization_options', v:null),
\ 'whitelist': lsp_settings#get('rls', 'whitelist', ['rust']),
\ 'blacklist': lsp_settings#get('rls', 'blacklist', []),
diff --git a/setting/solargraph.vim b/setting/solargraph.vim
index 914fb62..f86be72 100644
--- a/setting/solargraph.vim
+++ b/setting/solargraph.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_solargraph
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'solargraph',
- \ 'cmd': lsp_settings#get('solargraph', 'cmd', {server_info->[&shell, &shellcmdflag, 'solargraph stdio']}),
+ \ 'cmd': lsp_settings#get('solargraph', 'cmd', {server_info->[lsp_settings#exec_path('solargraph'), 'stdio']}),
\ 'initialization_options': lsp_settings#get('solargraph', 'initialization_options', {"diagnostics": "true"}),
\ 'whitelist': lsp_settings#get('solargraph', 'whitelist', ['ruby']),
\ 'blacklist': lsp_settings#get('solargraph', 'blacklist', []),
diff --git a/setting/typescript-language-server.vim b/setting/typescript-language-server.vim
index 4f2fcc0..ab7009d 100644
--- a/setting/typescript-language-server.vim
+++ b/setting/typescript-language-server.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_typescript_language_server
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'typescript-language-server',
- \ 'cmd': lsp_settings#get('typescript-language-server', {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']}),
+ \ 'cmd': lsp_settings#get('typescript-language-server', {server_info->[lsp_settings#exec_path('typescript-language-server'), '--stdio']}),
\ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'tsconfig.json'))},
\ 'initialization_options': lsp_settings#get('typescript-language-server', 'initialization_options', {"diagnostics": "true"}),
\ 'whitelist': lsp_settings#get('typescript-language-server', 'whitelist', ['typescript', 'typescript.tsx']),
diff --git a/setting/vim-language-server.vim b/setting/vim-language-server.vim
index 3be4af7..6932aa9 100644
--- a/setting/vim-language-server.vim
+++ b/setting/vim-language-server.vim
@@ -2,7 +2,7 @@ augroup vimlsp_settings_vim_language_server
au!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'vim-language-server',
- \ 'cmd': {server_info->[&shell, &shellcmdflag, 'vim-language-server --stdio']},
+ \ 'cmd': {server_info->[lsp_settings#exec_path('vim-language-server'), '--stdio']},
\ 'initialization_options': {
\ 'vimruntime': $VIMRUNTIME,
\ 'runtimepath': &rtp,