diff options
author | w0rp <devw0rp@gmail.com> | 2018-03-06 10:23:49 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2018-03-06 10:23:55 +0000 |
commit | 0a0535546f4d9a0dfe02671630fdaba72ea5828d (patch) | |
tree | 4030efd6be03a941d4c1e247a13d3d1d782d8b27 /autoload | |
parent | b7363bef7d8bdd553f10a6a168f4cd814616f6f9 (diff) | |
download | ale-0a0535546f4d9a0dfe02671630fdaba72ea5828d.zip |
Add a command for stopping all LSP clients
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/definition.vim | 4 | ||||
-rw-r--r-- | autoload/ale/engine.vim | 13 | ||||
-rw-r--r-- | autoload/ale/lsp.vim | 14 | ||||
-rw-r--r-- | autoload/ale/lsp/reset.vim | 25 |
4 files changed, 52 insertions, 4 deletions
diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim index b20c01a0..521cd0b1 100644 --- a/autoload/ale/definition.vim +++ b/autoload/ale/definition.vim @@ -19,6 +19,10 @@ function! ale#definition#Execute(expr) abort execute a:expr endfunction +function! ale#definition#ClearLSPData() abort + let s:go_to_definition_map = {} +endfunction + function! ale#definition#Open(options, filename, line, column) abort if a:options.open_in_tab call ale#definition#Execute('tabedit ' . fnameescape(a:filename)) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 6ccc3a34..89169874 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -76,6 +76,11 @@ function! ale#engine#InitBufferInfo(buffer) abort return 0 endfunction +" Clear LSP linter data for the linting engine. +function! ale#engine#ClearLSPData() abort + let s:lsp_linter_map = {} +endfunction + " This function is documented and part of the public API. " " Return 1 if ALE is busy checking a given buffer @@ -144,7 +149,7 @@ function! s:GatherOutput(job_id, line) abort endif endfunction -function! s:HandleLoclist(linter_name, buffer, loclist) abort +function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort let l:info = get(g:ale_buffer_info, a:buffer, {}) if empty(l:info) @@ -223,7 +228,7 @@ function! s:HandleExit(job_id, exit_code) abort let l:loclist = ale#util#GetFunction(l:linter.callback)(l:buffer, l:output) - call s:HandleLoclist(l:linter.name, l:buffer, l:loclist) + call ale#engine#HandleLoclist(l:linter.name, l:buffer, l:loclist) endfunction function! s:HandleLSPDiagnostics(conn_id, response) abort @@ -237,7 +242,7 @@ function! s:HandleLSPDiagnostics(conn_id, response) abort let l:loclist = ale#lsp#response#ReadDiagnostics(a:response) - call s:HandleLoclist(l:linter_name, l:buffer, l:loclist) + call ale#engine#HandleLoclist(l:linter_name, l:buffer, l:loclist) endfunction function! s:HandleTSServerDiagnostics(response, error_type) abort @@ -262,7 +267,7 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort let l:loclist = get(l:info, 'semantic_loclist', []) \ + get(l:info, 'syntax_loclist', []) - call s:HandleLoclist('tsserver', l:buffer, l:loclist) + call ale#engine#HandleLoclist('tsserver', l:buffer, l:loclist) endfunction function! s:HandleLSPErrorMessage(error_message) abort diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 126d6c18..8db9348f 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -325,6 +325,20 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback) abort return 1 endfunction +" Stop all LSP connections, closing all jobs and channels, and removing any +" queued messages. +function! ale#lsp#StopAll() abort + for l:conn in s:connections + if has_key(l:conn, 'channel') + call ch_close(l:conn.channel) + else + call ale#job#Stop(l:conn.id) + endif + endfor + + let s:connections = [] +endfunction + function! s:SendMessageData(conn, data) abort if has_key(a:conn, 'executable') call ale#job#SendRaw(a:conn.id, a:data) diff --git a/autoload/ale/lsp/reset.vim b/autoload/ale/lsp/reset.vim new file mode 100644 index 00000000..c206ed08 --- /dev/null +++ b/autoload/ale/lsp/reset.vim @@ -0,0 +1,25 @@ +" 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. + call ale#definition#ClearLSPData() + endif + + if exists('*ale#engine#ClearLSPData') + " Clear the mapping for connections, etc. + call ale#engine#ClearLSPData() + + " Remove the problems for all of the LSP linters in every buffer. + for l:buffer_string in keys(g:ale_buffer_info) + let l:buffer = str2nr(l:buffer_string) + + for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype')) + if !empty(l:linter.lsp) + call ale#engine#HandleLoclist(l:linter.name, l:buffer, []) + endif + endfor + endfor + endif +endfunction |