]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/lsp/reset.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / lsp / reset.vim
1 " Author: w0rp <dev@w0rp.com>
2 " Description: Functions for resetting LSP servers.
3
4 function! s:Message(message) abort
5     call ale#util#Execute('echom ' . string(a:message))
6 endfunction
7
8 " Stop all LSPs and remove all of the data for them.
9 function! ale#lsp#reset#StopAllLSPs() abort
10     call ale#lsp#StopAll()
11
12     if exists('*ale#definition#ClearLSPData')
13         " Clear the go to definition mapping for everything.
14         call ale#definition#ClearLSPData()
15     endif
16
17     if exists('*ale#lsp_linter#ClearLSPData')
18         " Clear the mapping for connections, etc.
19         call ale#lsp_linter#ClearLSPData()
20
21         " Remove the problems for all of the LSP linters in every buffer.
22         for l:buffer_string in keys(g:ale_buffer_info)
23             let l:buffer = str2nr(l:buffer_string)
24
25             " Non-ignored and disabled linters are included here so we can
26             " clear results for them after we ignore or disable them.
27             for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype'))
28                 if !empty(l:linter.lsp)
29                     call ale#engine#HandleLoclist(l:linter.name, l:buffer, [], 0)
30                 endif
31             endfor
32         endfor
33     endif
34 endfunction
35
36 function! ale#lsp#reset#Complete(arg, line, pos) abort
37     let l:linter_map = ale#lsp_linter#GetLSPLinterMap()
38     let l:candidates = map(values(l:linter_map), {_, linter -> linter.name})
39     call uniq(sort(l:candidates))
40     call filter(l:candidates, {_, name -> name =~? a:arg})
41
42     return l:candidates
43 endfunction
44
45 function! ale#lsp#reset#StopLSP(name, bang) abort
46     let l:linter_map = ale#lsp_linter#GetLSPLinterMap()
47     let l:matched = filter(
48     \   items(l:linter_map),
49     \   {_, item -> item[1].name is# a:name}
50     \)
51
52     if empty(l:matched)
53         if a:bang isnot# '!'
54             call s:Message('No running language server with name: ' . a:name)
55         endif
56
57         return
58     endif
59
60     " Stop LSP connections first.
61     for [l:conn_id, l:linter] in l:matched
62         call ale#lsp#Stop(l:conn_id)
63     endfor
64
65     if exists('*ale#definition#ClearLSPData')
66         " Clear the go to definition mapping for everything.
67         call ale#definition#ClearLSPData()
68     endif
69
70     " Remove connections from the lsp_linter map.
71     for [l:conn_id, l:linter] in l:matched
72         call remove(l:linter_map, l:conn_id)
73     endfor
74
75     " Remove the problems for the LSP linters in every buffer.
76     for [l:buffer_string, l:info] in items(g:ale_buffer_info)
77         let l:buffer = str2nr(l:buffer_string)
78         let l:should_clear_buffer = 0
79
80         for l:item in l:info.loclist
81             if l:item.linter_name is# a:name
82                 let l:should_clear_buffer = 1
83
84                 break
85             endif
86         endfor
87
88         if l:should_clear_buffer
89             call ale#engine#HandleLoclist(a:name, l:buffer, [], 0)
90         endif
91     endfor
92 endfunction