diff options
author | w0rp <devw0rp@gmail.com> | 2023-09-16 17:03:02 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2023-09-16 17:03:02 +0100 |
commit | 1799f8bec63508fb103236cacefb60a5e5100be1 (patch) | |
tree | d06e57b5a0f0854abe66a2f0aad62535c0739d78 /autoload/ale/lsp/reset.vim | |
parent | be69af270547b0d1dd5fe947efb3f61455f709ed (diff) | |
download | ale-1799f8bec63508fb103236cacefb60a5e5100be1.zip |
Close #4458 - Add an ALEStopLSP command
Add an ALEStopLSP command to stop all language servers that match a
given name. Completions are available for the command. This makes it
possible to keep other language servers running other than the one
you're interested in stopping.
Diffstat (limited to 'autoload/ale/lsp/reset.vim')
-rw-r--r-- | autoload/ale/lsp/reset.vim | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/autoload/ale/lsp/reset.vim b/autoload/ale/lsp/reset.vim index 85188b5a..1801db01 100644 --- a/autoload/ale/lsp/reset.vim +++ b/autoload/ale/lsp/reset.vim @@ -1,9 +1,16 @@ +" Author: w0rp <dev@w0rp.com> +" Description: Functions for resetting LSP servers. + +function! s:Message(message) abort + call ale#util#Execute('echom ' . string(a:message)) +endfunction + " Stop all LSPs and remove all of the data for them. function! ale#lsp#reset#StopAllLSPs() abort call ale#lsp#StopAll() if exists('*ale#definition#ClearLSPData') - " Clear the mapping for connections, etc. + " Clear the go to definition mapping for everything. call ale#definition#ClearLSPData() endif @@ -25,3 +32,61 @@ function! ale#lsp#reset#StopAllLSPs() abort endfor endif endfunction + +function! ale#lsp#reset#Complete(arg, line, pos) abort + let l:linter_map = ale#lsp_linter#GetLSPLinterMap() + let l:candidates = map(values(l:linter_map), {_, linter -> linter.name}) + call uniq(sort(l:candidates)) + call filter(l:candidates, {_, name -> name =~? a:arg}) + + return l:candidates +endfunction + +function! ale#lsp#reset#StopLSP(name, bang) abort + let l:linter_map = ale#lsp_linter#GetLSPLinterMap() + let l:matched = filter( + \ items(l:linter_map), + \ {_, item -> item[1].name is# a:name} + \) + + if empty(l:matched) + if a:bang isnot# '!' + call s:Message('No running language server with name: ' . a:name) + endif + + return + endif + + " Stop LSP connections first. + for [l:conn_id, l:linter] in l:matched + call ale#lsp#Stop(l:conn_id) + endfor + + if exists('*ale#definition#ClearLSPData') + " Clear the go to definition mapping for everything. + call ale#definition#ClearLSPData() + endif + + " Remove connections from the lsp_linter map. + for [l:conn_id, l:linter] in l:matched + call remove(l:linter_map, l:conn_id) + endfor + + " Remove the problems for the LSP linters in every buffer. + for [l:buffer_string, l:info] in items(g:ale_buffer_info) + let l:buffer = str2nr(l:buffer_string) + let l:should_clear_buffer = 0 + + for l:item in l:info.loclist + if l:item.linter_name is# a:name + let l:should_clear_buffer = 1 + + break + endif + endfor + + if l:should_clear_buffer + call ale#engine#HandleLoclist(a:name, l:buffer, [], 0) + endif + endfor +endfunction |