fix(lsp): handle nil request in semantic tokens #36780

Allow the `request` parameter in `tokens_to_ranges` to be `nil` and
update version checking logic accordingly. This prevents errors when
the request is not present and improves robustness of semantic token
handling.
This commit is contained in:
Tristan Knight
2025-12-01 17:51:04 +00:00
committed by GitHub
parent 8ede293b8a
commit 1de77c608f

View File

@@ -80,7 +80,7 @@ end
---@param data integer[] ---@param data integer[]
---@param bufnr integer ---@param bufnr integer
---@param client vim.lsp.Client ---@param client vim.lsp.Client
---@param request STActiveRequest ---@param request STActiveRequest | nil
---@return STTokenRange[] ---@return STTokenRange[]
local function tokens_to_ranges(data, bufnr, client, request) local function tokens_to_ranges(data, bufnr, client, request)
local legend = client.server_capabilities.semanticTokensProvider.legend local legend = client.server_capabilities.semanticTokensProvider.legend
@@ -108,7 +108,7 @@ local function tokens_to_ranges(data, bufnr, client, request)
vim.schedule(function() vim.schedule(function()
coroutine.resume(co, util.buf_versions[bufnr]) coroutine.resume(co, util.buf_versions[bufnr])
end) end)
if request.version ~= coroutine.yield() then if not request or request.version ~= coroutine.yield() then
-- request became stale since the last time the coroutine ran. -- request became stale since the last time the coroutine ran.
-- abandon it by yielding without a way to resume -- abandon it by yielding without a way to resume
coroutine.yield() coroutine.yield()