#3600 Implement pull model with Neovim Client
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled

Implement the diagnostics pull model with the LSP Neovim client. We
must handle messages a little different and tweak client capabilities
for pull diagnostics to work through the Neovim client.
This commit is contained in:
w0rp
2025-03-23 16:08:18 +00:00
parent f90e72ae1f
commit dd23b92ee9
3 changed files with 208 additions and 33 deletions

View File

@@ -38,13 +38,36 @@ module.start = function(config)
-- 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
})
vim.fn["ale#lsp_linter#HandleLSPDiagnostics"](
config.name,
result.uri,
result.diagnostics
)
end
end
end,
-- Handle pull model diagnostic data.
["textDocument/diagnostic"] = function(err, result, request, _)
if err == nil then
local diagnostics
if result.kind == "unchanged" then
diagnostics = "unchanged"
else
diagnostics = result.items
end
vim.fn["ale#lsp_linter#HandleLSPDiagnostics"](
config.name,
request.params.textDocument.uri,
diagnostics
)
end
end,
-- When the pull model is enabled we have to handle and return
-- some kind of data for a server diagnostic refresh request.
["workspace/diagnostic/refresh"] = function()
return {}
end,
}
config.on_init = function(client, _)
@@ -70,6 +93,16 @@ module.start = function(config)
return vim.fn["ale#lsp#GetLanguage"](config.name, bufnr)
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- Language servers like Pyright do not enable the diagnostics pull model
-- unless dynamicRegistration is enabled for diagnostics.
if capabilities.textDocument.diagnostic ~= nil then
capabilities.textDocument.diagnostic.dynamicRegistration = true
config.capabilities = capabilities
end
---@diagnostic disable-next-line: missing-fields
return vim.lsp.start(config, {
attach = false,
silent = true,
@@ -93,6 +126,10 @@ end
module.send_message = function(args)
local client = vim.lsp.get_client_by_id(args.client_id)
if client == nil then
return 0
end
if args.is_notification then
-- For notifications we send a request and expect no direct response.
local success = client.notify(args.method, args.params)