mirror of
https://github.com/neovim/neovim.git
synced 2026-08-27 09:31:47 +00:00
feat(lsp): support refreshing workspace diagnostics
This commit is contained in:
@@ -395,9 +395,17 @@ function M.on_refresh(err, _, ctx)
|
|||||||
if err then
|
if err then
|
||||||
return vim.NIL
|
return vim.NIL
|
||||||
end
|
end
|
||||||
for bufnr in pairs(vim.lsp.get_client_by_id(ctx.client_id).attached_buffers or {}) do
|
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||||
if bufstates[bufnr] and bufstates[bufnr].pull_kind == 'document' then
|
if
|
||||||
refresh(bufnr)
|
client.server_capabilities.diagnosticProvider
|
||||||
|
and client.server_capabilities.diagnosticProvider.workspaceDiagnostics
|
||||||
|
then
|
||||||
|
M._workspace_diagnostics(ctx)
|
||||||
|
else
|
||||||
|
for bufnr in pairs(client.attached_buffers or {}) do
|
||||||
|
if bufstates[bufnr] and bufstates[bufnr].pull_kind == 'document' then
|
||||||
|
refresh(bufnr)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -673,5 +673,52 @@ describe('vim.lsp.diagnostic', function()
|
|||||||
eq(1, #diags)
|
eq(1, #diags)
|
||||||
eq(2, diags[1].severity)
|
eq(2, diags[1].severity)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('refreshes workspace diagnostics', function()
|
||||||
|
local fake_uri_3 = 'file:///fake/uri3'
|
||||||
|
exec_lua(create_server_definition)
|
||||||
|
exec_lua(function()
|
||||||
|
_G.requests = 0
|
||||||
|
_G.server = _G._create_server({
|
||||||
|
capabilities = {
|
||||||
|
diagnosticProvider = { workspaceDiagnostics = true },
|
||||||
|
},
|
||||||
|
handlers = {
|
||||||
|
['workspace/diagnostic'] = function(_, _, callback)
|
||||||
|
_G.requests = _G.requests + 1
|
||||||
|
callback(nil, {
|
||||||
|
items = {
|
||||||
|
{
|
||||||
|
kind = 'full',
|
||||||
|
uri = fake_uri_3,
|
||||||
|
items = {
|
||||||
|
_G.make_error('Workspace Diagnostic', 4, 4, 4, 4),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
client_id = vim.lsp.start({ name = 'dummy', cmd = _G.server.cmd })
|
||||||
|
end)
|
||||||
|
|
||||||
|
local diags = exec_lua(function()
|
||||||
|
return vim.diagnostic.get()
|
||||||
|
end)
|
||||||
|
eq(0, #diags)
|
||||||
|
|
||||||
|
local requests, diags = exec_lua(function()
|
||||||
|
vim.lsp.diagnostic.on_refresh(nil, nil, {
|
||||||
|
method = 'workspace/diagnostic/refresh',
|
||||||
|
client_id = client_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
return _G.requests, vim.diagnostic.get()
|
||||||
|
end)
|
||||||
|
eq(1, requests)
|
||||||
|
eq(1, #diags)
|
||||||
|
eq(1, diags[1].severity)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user