fix(lsp): refresh document-pull buffers on workspace/diagnostic/refresh #40623

When a server supports both document and workspace pull diagnostics,
`on_refresh` only dispatched a `workspace/diagnostic` request.  The
workspace response handler skips buffers with `pull_kind == "document"`
(i.e. all buffers opened by the user), so their diagnostics went stale
until the next `didChange` or `didOpen` event.

Change `on_refresh` to always refresh document-pull buffers via
`textDocument/diagnostic`, regardless of whether the server also
supports workspace diagnostics.  This ensures that opened buffers
see updated diagnostics (e.g. after a save triggers an external
tool like PHPStan) without requiring the user to re-enter insert
mode.
This commit is contained in:
Caleb White
2026-07-08 06:26:22 -05:00
committed by GitHub
parent cfd7f29d52
commit 653f2092ce
2 changed files with 65 additions and 20 deletions

View File

@@ -405,13 +405,16 @@ function M.on_refresh(err, _, ctx)
end
if client:supports_method('workspace/diagnostic') then
M._workspace_diagnostics({ client_id = ctx.client_id })
else
for bufnr in pairs(client.attached_buffers or {}) do
local provider = Diagnostics.active[bufnr]
local state = provider and provider.client_state[ctx.client_id]
if state and state.pull_kind == 'document' then
provider:refresh(ctx.client_id)
end
end
-- Always refresh document-pull buffers. Workspace diagnostics only cover
-- buffers with pull_kind == 'workspace', so open buffers must be refreshed
-- individually or their diagnostics go stale until the next didChange.
for bufnr in pairs(client.attached_buffers or {}) do
local provider = Diagnostics.active[bufnr]
local state = provider and provider.client_state[ctx.client_id]
if state and state.pull_kind == 'document' then
provider:refresh(ctx.client_id)
end
end