diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-04-30 16:11:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-30 17:11:38 +0200 |
commit | 19a793545f15bb7e0bac2fc8f705c600e8f9c9bb (patch) | |
tree | 9fd9adc5f9c321469acbf7631241bf929ad5c451 /test/functional/treesitter/highlight_spec.lua | |
parent | 7e3d6ff4053b47a92067f7d68ba6f541ea89dee0 (diff) | |
download | rneovim-19a793545f15bb7e0bac2fc8f705c600e8f9c9bb.tar.gz rneovim-19a793545f15bb7e0bac2fc8f705c600e8f9c9bb.tar.bz2 rneovim-19a793545f15bb7e0bac2fc8f705c600e8f9c9bb.zip |
fix(treesitter): redraw added/removed injections properly (#23287)
When injections are added or removed make sure to:
- invoke 'changedtree' callbacks for when new trees are added.
- invoke 'changedtree' callbacks for when trees are invalidated
- redraw regions when languagetree children are removed
Diffstat (limited to 'test/functional/treesitter/highlight_spec.lua')
-rw-r--r-- | test/functional/treesitter/highlight_spec.lua | 82 |
1 files changed, 72 insertions, 10 deletions
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index 4e1efec404..dc303c564f 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -11,7 +11,7 @@ local eq = helpers.eq before_each(clear) -local hl_query = [[ +local hl_query_c = [[ (ERROR) @error "if" @keyword @@ -47,7 +47,7 @@ local hl_query = [[ (comment) @comment ]] -local hl_text = [[ +local hl_text_c = [[ /// Schedule Lua callback on main loop's event queue static int nlua_schedule(lua_State *const lstate) { @@ -64,7 +64,7 @@ static int nlua_schedule(lua_State *const lstate) return 0; }]] -local test_text = [[ +local test_text_c = [[ void ui_refresh(void) { int width = INT_MAX, height = INT_MAX; @@ -85,7 +85,7 @@ void ui_refresh(void) } }]] -describe('treesitter highlighting', function() +describe('treesitter highlighting (C)', function() local screen before_each(function() @@ -105,13 +105,13 @@ describe('treesitter highlighting', function() [11] = {foreground = Screen.colors.Cyan4}; } - exec_lua([[ hl_query = ... ]], hl_query) + exec_lua([[ hl_query = ... ]], hl_query_c) command [[ hi link @error ErrorMsg ]] command [[ hi link @warning WarningMsg ]] end) it('is updated with edits', function() - insert(hl_text) + insert(hl_text_c) screen:expect{grid=[[ /// Schedule Lua callback on main loop's event queue | static int nlua_schedule(lua_State *const lstate) | @@ -274,7 +274,7 @@ describe('treesitter highlighting', function() end) it('is updated with :sort', function() - insert(test_text) + insert(test_text_c) exec_lua [[ local parser = vim.treesitter.get_parser(0, "c") test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query}}) @@ -351,7 +351,7 @@ describe('treesitter highlighting', function() [1] = {bold = true, foreground = Screen.colors.SeaGreen4}; } - insert(test_text) + insert(test_text_c) screen:expect{ grid= [[ int width = INT_MAX, height = INT_MAX; | @@ -510,7 +510,7 @@ describe('treesitter highlighting', function() end) it("supports highlighting with custom highlight groups", function() - insert(hl_text) + insert(hl_text_c) exec_lua [[ local parser = vim.treesitter.get_parser(0, "c") @@ -692,7 +692,7 @@ describe('treesitter highlighting', function() end) it("supports conceal attribute", function() - insert(hl_text) + insert(hl_text_c) -- conceal can be empty or a single cchar. exec_lua [=[ @@ -753,3 +753,65 @@ describe('treesitter highlighting', function() eq(nil, get_hl"@total.nonsense.but.a.lot.of.dots") end) end) + +describe('treesitter highlighting (help)', function() + local screen + + before_each(function() + screen = Screen.new(40, 6) + screen:attach() + screen:set_default_attr_ids { + [1] = {foreground = Screen.colors.Blue1}; + [2] = {bold = true, foreground = Screen.colors.Blue1}; + [3] = {bold = true, foreground = Screen.colors.Brown}; + [4] = {foreground = Screen.colors.Cyan4}; + [5] = {foreground = Screen.colors.Magenta1}; + } + end) + + it("correctly redraws added/removed injections", function() + insert[[ + >ruby + -- comment + local this_is = 'actually_lua' + < + ]] + + exec_lua [[ + vim.bo.filetype = 'help' + vim.treesitter.start() + ]] + + screen:expect{grid=[[ + {1:>ruby} | + {1: -- comment} | + {1: local this_is = 'actually_lua'} | + < | + ^ | + | + ]]} + + helpers.curbufmeths.set_text(0, 1, 0, 5, {'lua'}) + + screen:expect{grid=[[ + {1:>lua} | + {1: -- comment} | + {1: }{3:local}{1: }{4:this_is}{1: }{3:=}{1: }{5:'actually_lua'} | + < | + ^ | + | + ]]} + + helpers.curbufmeths.set_text(0, 1, 0, 4, {'ruby'}) + + screen:expect{grid=[[ + {1:>ruby} | + {1: -- comment} | + {1: local this_is = 'actually_lua'} | + < | + ^ | + | + ]]} + end) + +end) |