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.
This commit is contained in:
w0rp
2023-09-16 17:03:02 +01:00
parent be69af2705
commit 1799f8bec6
5 changed files with 216 additions and 46 deletions

View File

@@ -5,6 +5,7 @@ Before:
Save g:ale_set_loclist
Save g:ale_set_highlights
Save g:ale_echo_cursor
Save g:ale_buffer_info
let g:ale_enabled = 0
let g:ale_set_signs = 0
@@ -12,14 +13,20 @@ Before:
let g:ale_set_loclist = 0
let g:ale_set_highlights = 0
let g:ale_echo_cursor = 0
let g:expr_list = []
function EmptyString() abort
return ''
endfunction
runtime autoload/ale/util.vim
function! ale#util#Execute(expr) abort
call add(g:expr_list, a:expr)
endfunction
call ale#engine#InitBufferInfo(bufnr(''))
" Call this function first, so we can be sure the module is loaded before we
" check if it exists.
" Call this function first, to clear LSP data.
call ale#lsp_linter#ClearLSPData()
call ale#linter#Define('testft', {
@@ -30,7 +37,14 @@ Before:
\ 'project_root': function('EmptyString'),
\ 'language': function('EmptyString'),
\})
call ale#linter#Define('testft', {
\ 'name': 'lsplinter2',
\ 'lsp': 'tsserver',
\ 'executable': function('EmptyString'),
\ 'command': function('EmptyString'),
\ 'project_root': function('EmptyString'),
\ 'language': function('EmptyString'),
\})
call ale#linter#Define('testft', {
\ 'name': 'otherlinter',
\ 'callback': 'TestCallback',
@@ -42,34 +56,23 @@ Before:
After:
Restore
delfunction EmptyString
unlet! g:expr_list
unlet! b:ale_save_event_fired
delfunction EmptyString
" Clear LSP data after tests.
call ale#lsp_linter#ClearLSPData()
runtime autoload/ale/util.vim
call ale#linter#Reset()
Given testft(Some file with an imaginary filetype):
Execute(ALEStopAllLSPs should clear the loclist):
" For these tests we only need to set the keys we need.
let g:ale_buffer_info[bufnr('')].loclist = [
\ {
\ 'text': 'a',
\ 'lnum': 10,
\ 'col': 0,
\ 'bufnr': bufnr(''),
\ 'vcol': 0,
\ 'type': 'E',
\ 'nr': -1,
\ 'linter_name': 'lsplinter',
\ },
\ {
\ 'text': 'a',
\ 'lnum': 10,
\ 'col': 0,
\ 'bufnr': bufnr(''),
\ 'vcol': 0,
\ 'type': 'E',
\ 'nr': -1,
\ 'linter_name': 'otherlinter',
\ },
\ {'linter_name': 'lsplinter'},
\ {'linter_name': 'otherlinter'},
\]
let g:ale_buffer_info[bufnr('')].active_linter_list = [
\ {'name': 'lsplinter'},
@@ -79,20 +82,88 @@ Execute(ALEStopAllLSPs should clear the loclist):
ALEStopAllLSPs
" The loclist should be updated.
AssertEqual g:ale_buffer_info[bufnr('')].loclist, [
\ {
\ 'text': 'a',
\ 'lnum': 10,
\ 'col': 0,
\ 'bufnr': bufnr(''),
\ 'vcol': 0,
\ 'type': 'E',
\ 'nr': -1,
\ 'linter_name': 'otherlinter',
\ },
\]
AssertEqual
\ ['otherlinter'],
\ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
" The LSP linter should be removed from the active linter list.
AssertEqual
\ ['otherlinter'],
\ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
Execute(ALEStopLSP should stop a named LSP):
let g:ale_buffer_info[bufnr('')].loclist = [
\ {'linter_name': 'lsplinter'},
\ {'linter_name': 'lsplinter2'},
\ {'linter_name': 'otherlinter'},
\]
let g:ale_buffer_info[bufnr('')].active_linter_list = [
\ {'name': 'lsplinter'},
\ {'name': 'lsplinter2'},
\ {'name': 'otherlinter'},
\]
call ale#lsp_linter#SetLSPLinterMap({
\ 'conn1': {'name': 'lsplinter'},
\ 'conn2': {'name': 'lsplinter2'},
\ 'conn3': {'name': 'lsplinter'},
\})
ALEStopLSP lsplinter
" We should remove only the items for this linter.
AssertEqual
\ ['lsplinter2', 'otherlinter'],
\ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
" The linter should be removed from the active linter list.
AssertEqual
\ ['lsplinter2', 'otherlinter'],
\ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
" The connections linters with this name should be removed.
AssertEqual
\ {'conn2': {'name': 'lsplinter2'}},
\ ale#lsp_linter#GetLSPLinterMap()
Execute(ALEStopLSP should not clear results for linters not running):
let g:ale_buffer_info[bufnr('')].loclist = [
\ {'linter_name': 'lsplinter'},
\ {'linter_name': 'otherlinter'},
\]
let g:ale_buffer_info[bufnr('')].active_linter_list = [
\ {'name': 'lsplinter'},
\ {'name': 'otherlinter'},
\]
ALEStopLSP lsplinter
" We should emit a message saying the server isn't running.
AssertEqual
\ ['echom ''No running language server with name: lsplinter'''],
\ g:expr_list
" We should keep the linter items.
AssertEqual
\ ['lsplinter', 'otherlinter'],
\ map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.linter_name')
AssertEqual
\ ['lsplinter', 'otherlinter'],
\ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
Execute(ALEStopLSP with a bang should not emit warnings):
ALEStopLSP! lsplinter
AssertEqual [], g:expr_list
Execute(ALEStopLSP's completion function should suggest running linter names):
call ale#lsp_linter#SetLSPLinterMap({
\ 'conn1': {'name': 'pyright'},
\ 'conn2': {'name': 'pylsp'},
\ 'conn3': {'name': 'imaginaryserver'},
\})
AssertEqual
\ ['imaginaryserver', 'pylsp', 'pyright'],
\ ale#lsp#reset#Complete('', '', 42)
AssertEqual ['imaginaryserver'], ale#lsp#reset#Complete('inary', '', 42)
AssertEqual ['pylsp'], ale#lsp#reset#Complete('LSP', '', 42)