mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Clean up message handling for LSP integration
Now we ought to be able to handle any kind of response for any request we send, clean up message handling so there are fewer changes to make to LSP code to adjust for Neovim integration.
This commit is contained in:
@@ -497,19 +497,13 @@ function! s:CheckWithLSP(linter, details) abort
|
|||||||
|
|
||||||
let l:id = a:details.connection_id
|
let l:id = a:details.connection_id
|
||||||
|
|
||||||
" Remember the linter this connection is for.
|
|
||||||
let s:lsp_linter_map[l:id] = a:linter
|
|
||||||
|
|
||||||
if g:ale_use_neovim_lsp_api && a:linter.lsp isnot# 'tsserver'
|
|
||||||
" If running an LSP client via Neovim's API then Neovim will
|
|
||||||
" internally track buffers for changes for us, and we can stop here.
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Register a callback now for handling errors now.
|
" Register a callback now for handling errors now.
|
||||||
let l:Callback = function('ale#lsp_linter#HandleLSPResponse')
|
let l:Callback = function('ale#lsp_linter#HandleLSPResponse')
|
||||||
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|
||||||
|
" Remember the linter this connection is for.
|
||||||
|
let s:lsp_linter_map[l:id] = a:linter
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
if a:linter.lsp is# 'tsserver'
|
||||||
let l:message = ale#lsp#tsserver_message#Geterr(l:buffer)
|
let l:message = ale#lsp#tsserver_message#Geterr(l:buffer)
|
||||||
let l:notified = ale#lsp#Send(l:id, l:message) != 0
|
let l:notified = ale#lsp#Send(l:id, l:message) != 0
|
||||||
@@ -517,17 +511,16 @@ function! s:CheckWithLSP(linter, details) abort
|
|||||||
if l:notified
|
if l:notified
|
||||||
call ale#engine#MarkLinterActive(l:info, a:linter)
|
call ale#engine#MarkLinterActive(l:info, a:linter)
|
||||||
endif
|
endif
|
||||||
else
|
elseif !g:ale_use_neovim_lsp_api
|
||||||
let l:notified = ale#lsp#NotifyForChanges(l:id, l:buffer)
|
let l:notified = ale#lsp#NotifyForChanges(l:id, l:buffer)
|
||||||
endif
|
|
||||||
|
|
||||||
" If this was a file save event, also notify the server of that.
|
" If this was a file save event, also notify the server of that.
|
||||||
if a:linter.lsp isnot# 'tsserver'
|
if getbufvar(l:buffer, 'ale_save_event_fired', 0)
|
||||||
\&& getbufvar(l:buffer, 'ale_save_event_fired', 0)
|
\&& ale#lsp#HasCapability(l:id, 'did_save')
|
||||||
\&& ale#lsp#HasCapability(l:id, 'did_save')
|
let l:include_text = ale#lsp#HasCapability(l:id, 'includeText')
|
||||||
let l:include_text = ale#lsp#HasCapability(l:id, 'includeText')
|
let l:save_message = ale#lsp#message#DidSave(l:buffer, l:include_text)
|
||||||
let l:save_message = ale#lsp#message#DidSave(l:buffer, l:include_text)
|
let l:notified = ale#lsp#Send(l:id, l:save_message) != 0
|
||||||
let l:notified = ale#lsp#Send(l:id, l:save_message) != 0
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -552,7 +545,6 @@ function! s:OnReadyForCustomRequests(args, linter, lsp_details) abort
|
|||||||
let l:id = a:lsp_details.connection_id
|
let l:id = a:lsp_details.connection_id
|
||||||
let l:request_id = ale#lsp#Send(l:id, a:args.message)
|
let l:request_id = ale#lsp#Send(l:id, a:args.message)
|
||||||
|
|
||||||
" TODO: Implement this whole flow with the lua API.
|
|
||||||
if l:request_id > 0 && has_key(a:args, 'handler')
|
if l:request_id > 0 && has_key(a:args, 'handler')
|
||||||
let l:Callback = function('s:HandleLSPResponseToCustomRequests')
|
let l:Callback = function('s:HandleLSPResponseToCustomRequests')
|
||||||
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|||||||
Reference in New Issue
Block a user