mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-16 23:14:27 +08:00
Handle Neovim LSP diagnostics via ALE's functions
This commit is contained in:
@@ -488,12 +488,6 @@ function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CheckWithLSP(linter, details) abort
|
function! s:CheckWithLSP(linter, details) abort
|
||||||
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
|
|
||||||
|
|
||||||
let l:buffer = a:details.buffer
|
let l:buffer = a:details.buffer
|
||||||
let l:info = get(g:ale_buffer_info, l:buffer)
|
let l:info = get(g:ale_buffer_info, l:buffer)
|
||||||
|
|
||||||
@@ -503,13 +497,19 @@ 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
|
||||||
|
|||||||
@@ -8,7 +8,26 @@ module.start = function(config)
|
|||||||
config.init_options[true] = nil
|
config.init_options[true] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.handlers = {
|
||||||
|
-- Override Neovim's handling of diagnostics to run through ALE's
|
||||||
|
-- functions so all of the functionality in ALE works.
|
||||||
|
["textDocument/publishDiagnostics"] = function(err, result, _, _)
|
||||||
|
if err == nil then
|
||||||
|
vim.fn["ale#lsp_linter#HandleLSPResponse"](config.name, {
|
||||||
|
jsonrpc = "2.0",
|
||||||
|
method = "textDocument/publishDiagnostics",
|
||||||
|
params = result
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
config.on_init = function(_, _)
|
config.on_init = function(_, _)
|
||||||
|
-- Neovim calls `on_init` before marking a client as active, meaning
|
||||||
|
-- we can't get a client via get_client_by_id until after `on_init` is
|
||||||
|
-- called. By deferring execution of calling the init callbacks we
|
||||||
|
-- can only call them after the client becomes available, which
|
||||||
|
-- will make notifications for configuration changes work, etc.
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
vim.fn["ale#lsp#CallInitCallbacks"](config.name)
|
vim.fn["ale#lsp#CallInitCallbacks"](config.name)
|
||||||
end, 0)
|
end, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user