From 7fa292c52d7bf63d59730946ef220befe4d51900 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 23 Dec 2023 19:45:19 +0900 Subject: fix(treesitter): outdated highlight due to tree with outdated region Problem: A region managed by an injected parser may shrink after re-running the injection query. If the updated region goes out of the range to be parsed, then the corresponding tree will remain outdated, possibly retaining the nodes that shouldn't exist anymore. This results in outdated highlights. Solution: Re-parse an invalid tree if its region intersects the range to be parsed. --- test/functional/treesitter/parser_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional') diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index 6f386115ae..94642552d9 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -693,6 +693,18 @@ int x = INT_MAX; {2, 26, 3, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) + + helpers.feed('7ggI//') + exec_lua([[parser:parse({6, 7})]]) + eq("table", exec_lua("return type(parser:children().c)")) + eq(2, exec_lua("return #parser:children().c:trees()")) + eq({ + {0, 0, 8, 0}, -- root tree + {4, 14, 5, 18}, -- VALUE 123 + -- VALUE1 123 + {2, 26, 3, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) + -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) + }, get_ranges()) end) end) -- cgit