aboutsummaryrefslogtreecommitdiff
path: root/plugin/lsp_setup.vim
blob: 29ec87f58634048d1965373f88efeca100d501fd (plain)
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
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_install_server() abort
  if empty(s:setting[&filetype])
    return
  endif
  let l:command = printf('%s/install-%s', s:installer_dir, s:setting[&filetype][0].command)
  if has('win32')
    let l:command = substitute(l:command, '/', '\', 'g') . '.cmd'
  else
    let l:command = substitute(l:command, '/', '\', 'g') . '.sh'
  endif
  exe 'terminal' l:command
endfunction

function! s:vimlsp_settings_suggest() abort
  echomsg printf("If you want to enable Language Server, please do :LspInstallServer")
  command -buffer LspInstallServer call s:vimlsp_install_server()
endfunction

function! s:vimlsp_setting() abort
  for l:ft in keys(s:setting)
    let l:found = 0
    if empty(s:setting[l:ft])
      continue
    endif
    for l:server in s:setting[l:ft]
      if 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
	  exe printf('augroup vimlsp_suggest_%s', l:ft)
	    au!
	    exe printf('autocmd FileType %s call s:vimlsp_settings_suggest()', l:ft)
	  augroup END
    endif
  endfor
endfunction

call s:vimlsp_setting()