aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua4
-rw-r--r--test/functional/treesitter/highlight_spec.lua64
2 files changed, 66 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index b2c4e9167d..670f2797b7 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -650,8 +650,8 @@ function LanguageTree:included_regions()
return self._regions
end
- if not self._has_regions or next(self._trees) == nil then
- -- treesitter.c will default empty ranges to { -1, -1, -1, -1, -1, -1}
+ if not self._has_regions then
+ -- treesitter.c will default empty ranges to { -1, -1, -1, -1, -1, -1} (the full range)
return { {} }
end
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index 0aa0cdd6d6..e037c9e215 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -838,3 +838,67 @@ describe('treesitter highlighting (help)', function()
end)
end)
+
+describe('treesitter highlighting (nested injections)', function()
+ local screen
+
+ before_each(function()
+ screen = Screen.new(80, 7)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = {foreground = Screen.colors.SlateBlue};
+ [2] = {bold = true, foreground = Screen.colors.Brown};
+ [3] = {foreground = Screen.colors.Cyan4};
+ [4] = {foreground = Screen.colors.Fuchsia};
+ }
+ end)
+
+ it("correctly redraws nested injections (GitHub #25252)", function()
+ insert[=[
+function foo() print("Lua!") end
+
+local lorem = {
+ ipsum = {},
+ bar = {},
+}
+vim.cmd([[
+ augroup RustLSP
+ autocmd CursorHold silent! lua vim.lsp.buf.document_highlight()
+ augroup END
+]])
+ ]=]
+
+ exec_lua [[
+ vim.opt.scrolloff = 0
+ vim.bo.filetype = 'lua'
+ vim.treesitter.start()
+ ]]
+
+ -- invalidate the language tree
+ feed("ggi--[[<ESC>04x")
+
+ screen:expect{grid=[[
+ {2:^function} {3:foo}{1:()} {1:print(}{4:"Lua!"}{1:)} {2:end} |
+ |
+ {2:local} {3:lorem} {2:=} {1:{} |
+ {3:ipsum} {2:=} {1:{},} |
+ {3:bar} {2:=} {1:{},} |
+ {1:}} |
+ |
+ ]]}
+
+ -- spam newline insert/delete to invalidate Lua > Vim > Lua region
+ feed("3jo<ESC>ddko<ESC>ddko<ESC>ddko<ESC>ddk0")
+
+ screen:expect{grid=[[
+ {2:function} {3:foo}{1:()} {1:print(}{4:"Lua!"}{1:)} {2:end} |
+ |
+ {2:local} {3:lorem} {2:=} {1:{} |
+ ^ {3:ipsum} {2:=} {1:{},} |
+ {3:bar} {2:=} {1:{},} |
+ {1:}} |
+ |
+ ]]}
+ end)
+
+end)