-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
lsp_settings.vim
79 lines (74 loc) · 2.08 KB
/
lsp_settings.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
let s:servers_dir = expand('<sfile>:h:h').'/servers'
function! lsp_settings#get(name, key, default) abort
let l:config = get(g:, 'lsp_settings', {})
if !has_key(l:config, a:name)
if !has_key(l:config, '*')
return a:default
endif
let l:config = l:config['*']
else
let l:config = l:config[a:name]
endif
if !has_key(l:config, a:key)
return a:default
endif
return l:config[a:key]
endfunction
function! s:first_one(cmd) abort
if empty(a:cmd)
return ''
endif
return fnamemodify(split(a:cmd, "\n")[0], ':p')
endfunction
function! lsp_settings#exec_path(cmd) abort
let l:paths = split($PATH, has('win32') ? ';' : ':')
let l:paths = join(l:paths, ',')
let l:path = globpath(l:paths, a:cmd)
if !has('win32')
if !empty(l:path)
return s:first_one(l:path)
endif
else
let l:path = globpath(l:paths, a:cmd . '.exe')
if !empty(l:path)
return s:first_one(l:path)
endif
let l:path = globpath(l:paths, a:cmd . '.cmd')
if !empty(l:path)
return s:first_one(l:path)
endif
let l:path = globpath(l:paths, a:cmd . '.bat')
if !empty(l:path)
return s:first_one(l:path)
endif
endif
let l:paths = get(g:, 'lsp_settings_extra_paths', '')
if type(l:paths) == type([])
let l:paths = join(l:paths, ',') . ','
endif
let l:servers_dir = get(g:, 'lsp_settings_servers_dir', s:servers_dir)
let l:paths .= l:servers_dir . '/' . a:cmd
if !has('win32')
return s:first_one(globpath(l:paths, a:cmd))
endif
let l:path = globpath(l:paths, a:cmd . '.exe')
if !empty(l:path)
return s:first_one(l:path)
endif
let l:path = globpath(l:paths, a:cmd . '.cmd')
if !empty(l:path)
return s:first_one(l:path)
endif
let l:path = globpath(l:paths, a:cmd . '.bat')
if !empty(l:path)
return s:first_one(l:path)
endif
return ''
endfunction
function! lsp_settings#root_uri(pattern) abort
let l:dir = lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), a:pattern)
if empty(l:dir)
return lsp#utils#get_default_root_uri()
endif
return lsp#utils#path_to_uri(l:dir)
endfunction