aboutsummaryrefslogtreecommitdiff
path: root/autoload/lsp_settings/profile.vim
blob: 4fd9315378cd9f7282f8dd0dbe280f0a8b32daa9 (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
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
function! lsp_settings#profile#load_local() abort
  try
    let l:root = lsp#utils#find_nearest_parent_directory('.', '.vim-lsp-settings')
    if !empty(l:root) && filereadable(l:root . '/settings.json')
      let l:settings = json_decode(join(readfile(l:root . '/settings.json'), "\n"))
      if  has_key(g:, 'lsp_settings')
        let g:lsp_settings = extend(g:lsp_settings, l:settings)
      else
        let g:lsp_settings = l:settings
      endif
    endif
  catch
  endtry
endfunction

function! lsp_settings#profile#edit_local() abort
  let l:root = lsp_settings#root_path(['.vim-lsp-settings'])
  if !isdirectory(l:root)
    return
  endif
  let l:root .= '/.vim-lsp-settings'
  if !isdirectory(l:root)
    call mkdir(l:root)
  endif
  exe 'new' l:root . '/settings.json'
  if !filereadable(l:root . '/settings.json')
    call setline(1, ['{', "\t", '}'])
    call cursor([2, 2])
    setlocal nomodified
  endif
endfunction

let s:color_map = {
\ 'exited': 'Error',
\ 'starting': 'MoreMsg',
\ 'failed': 'WarningMsg',
\ 'running': 'Keyword',
\ 'not running': 'NonText'
\}

function! lsp_settings#profile#status() abort
  let l:settings = lsp_settings#settings()
  let l:active_servers = lsp#get_whitelisted_servers()

  let l:servers = []
  for l:ft in keys(l:settings)
    for l:v in l:settings[l:ft]
      if index(l:servers, l:v.command) ==# -1
        call add(l:servers, l:v.command)
      endif
    endfor
  endfor

  for l:server in uniq(sort(l:servers))
    if index(l:active_servers, l:server) != -1
      let l:status = lsp#get_server_status(l:server)
      echon l:server . ': '
      exec 'echohl' s:color_map[l:status]
      echon l:status
      echohl None
    elseif lsp_settings#executable(l:server)
      echon l:server . ': '
      echohl vimFilter
      echon 'not running'
      echohl None
    else
      echon l:server . ': '
      echohl vimOption
      echon 'not installed'
      echohl None
    endif
    echo ''
  endfor
endfunction