aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/languagetree.lua
diff options
context:
space:
mode:
authorJaehwang Jung <tomtomjhj@gmail.com>2023-12-23 19:45:19 +0900
committerChristian Clason <c.clason@uni-graz.at>2023-12-24 09:47:59 +0100
commit7fa292c52d7bf63d59730946ef220befe4d51900 (patch)
tree16d7c067fcd0277133e14804f250f4b83d8367f7 /runtime/lua/vim/treesitter/languagetree.lua
parent0b66ab42c76c41494a9d7fc715d310f1a1da929d (diff)
downloadrneovim-7fa292c52d7bf63d59730946ef220befe4d51900.tar.gz
rneovim-7fa292c52d7bf63d59730946ef220befe4d51900.tar.bz2
rneovim-7fa292c52d7bf63d59730946ef220befe4d51900.zip
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.
Diffstat (limited to 'runtime/lua/vim/treesitter/languagetree.lua')
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua8
1 files changed, 7 insertions, 1 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 0171b416cd..a249a10f47 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -348,7 +348,13 @@ function LanguageTree:_parse_regions(range)
-- If there are no ranges, set to an empty list
-- so the included ranges in the parser are cleared.
for i, ranges in pairs(self:included_regions()) do
- if not self._valid[i] and intercepts_region(ranges, range) then
+ if
+ not self._valid[i]
+ and (
+ intercepts_region(ranges, range)
+ or (self._trees[i] and intercepts_region(self._trees[i]:included_ranges(false), range))
+ )
+ then
self._parser:set_included_ranges(ranges)
local parse_time, tree, tree_changes =
tcall(self._parser.parse, self._parser, self._trees[i], self._source, true)