fix(lsp): multiline semantic token processing #40339

Problem: When multiline semantic token support was introduced, the loop
that finds the end line for a particular token didn't sanitize the token
length sent back by the LSP server. If the server returned an overflowed
length (near uint32 max), neovim would burn cpu and loop for an
extremely long time while trying to find the "end line" represented by
the massively large token, causing neovim to seemingly hang.

Solution: Stop looping once the calculated end_line reaches the actual
last line of the buffer.

Fixes #36257
This commit is contained in:
jdrouhard
2026-06-20 09:51:21 -05:00
committed by GitHub
parent 69160854c5
commit 6bc6461eac
2 changed files with 34 additions and 1 deletions

View File

@@ -143,7 +143,7 @@ local function tokens_to_ranges(data, bufnr, client, request, ranges)
---@type integer LuaLS bug, type must be marked explicitly here
local new_end_char = end_char - vim.str_utfindex(buf_line, encoding) - eol_offset
-- While end_char goes past the given line, extend the token range to the next line
while new_end_char > 0 do
while new_end_char > 0 and end_line < #lines - 1 do
end_char = new_end_char
end_line = end_line + 1
buf_line = lines[end_line + 1] or ''