diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-11-09 08:40:27 +0000 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-11-09 09:41:12 +0000 |
commit | 4b001f297ae29654b86eccd4dde72b2cc314ca01 (patch) | |
tree | fa2df69ea8955e23eac9202e359737b3d5bb9720 /runtime/lua/vim/lsp/semantic_tokens.lua | |
parent | b7e1bbfb50c78352e31a6b27f430db3c8f4fbf1d (diff) | |
download | rneovim-4b001f297ae29654b86eccd4dde72b2cc314ca01.tar.gz rneovim-4b001f297ae29654b86eccd4dde72b2cc314ca01.tar.bz2 rneovim-4b001f297ae29654b86eccd4dde72b2cc314ca01.zip |
fix(lsp): fix infinite loop
Fixes #31129
Diffstat (limited to 'runtime/lua/vim/lsp/semantic_tokens.lua')
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 839ec8bea3..f23c694c4b 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -394,6 +394,23 @@ local function set_mark(bufnr, ns, token, hl_group, priority) }) end +--- @param lnum integer +--- @param foldend integer? +--- @return boolean, integer? +local function check_fold(lnum, foldend) + if foldend and lnum <= foldend then + return true, foldend + end + + local folded = vim.fn.foldclosed(lnum) + + if folded == -1 then + return false, nil + end + + return folded ~= lnum, vim.fn.foldclosedend(lnum) +end + --- on_win handler for the decoration provider (see |nvim_set_decoration_provider|) --- --- If there is a current result for the buffer and the version matches the @@ -462,15 +479,15 @@ function STHighlighter:on_win(topline, botline) local first = lower_bound(highlights, topline, 1, #highlights + 1) local last = upper_bound(highlights, botline, first, #highlights + 1) - 1 - local i = first - while i <= last do + --- @type boolean?, integer? + local is_folded, foldend + + for i = first, last do local token = highlights[i] - local folded = vim.fn.foldclosed(token.line + 1) - -- Do not highlight folded lines - local can_mark = folded == -1 or folded == token.line + 1 + is_folded, foldend = check_fold(token.line + 1, foldend) - if can_mark and not token.marked then + if not is_folded and not token.marked then set_mark0(token, string.format('@lsp.type.%s.%s', token.type, ft), 0) for modifier in pairs(token.modifiers) do set_mark0(token, string.format('@lsp.mod.%s.%s', modifier, ft), 1) @@ -487,12 +504,6 @@ function STHighlighter:on_win(topline, botline) }, }) end - - if folded ~= -1 then - i = math.min(last, vim.fn.foldclosedend(token.line + 1) - 1) - else - i = i + 1 - end end end end |