feat(lsp): support workspace/foldingRange/refresh #41780

Problem:
Servers cannot request refreshing stale LSP folding ranges after a
project-wide change.

Solution:
Advertise `workspace.foldingRange.refreshSupport` and re-request folding
ranges for active buffers when handling `workspace/foldingRange/refresh`.

AI-assisted
This commit is contained in:
Volodymyr Chernetskyi
2026-09-09 14:45:10 +02:00
committed by GitHub
parent 0a844adc13
commit 8e0045f43a
5 changed files with 57 additions and 1 deletions

View File

@@ -289,6 +289,26 @@ function State:foldclose(kind, winid)
end)
end
--- |lsp-handler| for the method `workspace/foldingRange/refresh`
---
--- Refresh requests are sent by the server to indicate a project-wide change
--- that requires all folding ranges to be re-requested by the client.
---@param ctx lsp.HandlerContext
---@internal
function M.on_refresh(err, _, ctx)
if err then
return vim.NIL
end
for _, state in pairs(State.active) do
if state.client_state[ctx.client_id] then
state:refresh(ctx.client_id)
end
end
return vim.NIL
end
---@param kind lsp.FoldingRangeKind
---@param winid? integer
function M.foldclose(kind, winid)

View File

@@ -673,6 +673,11 @@ RSC['workspace/diagnostic/refresh'] = function(err, result, ctx)
return vim.lsp.diagnostic.on_refresh(err, result, ctx)
end
---@see https://microsoft.github.io/language-server-protocol/specification/#workspace_foldingRange_refresh
RSC['workspace/foldingRange/refresh'] = function(err, result, ctx)
return vim.lsp._folding_range.on_refresh(err, result, ctx)
end
---@see https://microsoft.github.io/language-server-protocol/specification/#workspace_inlayHint_refresh
RSC['workspace/inlayHint/refresh'] = function(err, result, ctx)
return vim.lsp.inlay_hint.on_refresh(err, result, ctx)

View File

@@ -639,6 +639,9 @@ function protocol.make_client_capabilities()
diagnostics = {
refreshSupport = true,
},
foldingRange = {
refreshSupport = true,
},
fileOperations = {
dynamicRegistration = false,
didCreate = false,