diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 472b605e38..a5b60acc9b 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -561,7 +561,10 @@ function TSHighlighter._on_start() if not buf_ranges[buf] then buf_ranges[buf] = {} end - local topline, botline = vim.fn.line('w0', win) - 1, vim.fn.line('w$', win) + local topline = vim.fn.line('w0', win) - 1 + -- +1 because w$ is the last completely displayed line (w_botline - 1), which may be -1 of the + -- last line that is at least partially visible. + local botline = vim.fn.line('w$', win) + 1 table.insert(buf_ranges[buf], { topline, botline }) end end diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index 0251fc7b2c..eb76470b6d 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -357,7 +357,7 @@ describe('vim.lsp.util', function() screen:expect([[ ^ | ┌─────────┐{1: }| - │{101:local foo}│{1: }| + │{100:local}{101: }{102:foo}│{1: }| └─────────┘{1: }| {1:~ }|*9 | @@ -384,7 +384,7 @@ describe('vim.lsp.util', function() screen:expect([[ ^ | ┌─────────┐{1: }| - │{101:local foo}│{1: }| + │{100:local}{101: }{102:foo}│{1: }| └─────────┘{1: }| {1:~ }|*9 |