perf(treesitter): parse multiple ranges in languagetree, eliminate flickering #36503

**Problem:** Whenever `LanguageTree:parse()` is called, injection trees
from previously parsed ranges are dropped.

**Solution:** Allow the function to accept a list of ranges, so it can
return injection trees for all the given ranges.

Co-authored-by: Jaehwang Jung <tomtomjhj@gmail.com>
This commit is contained in:
Riley Bruins
2025-11-18 10:09:49 -08:00
committed by GitHub
parent 2483d5ad8a
commit 098da1fc2c
4 changed files with 166 additions and 95 deletions

View File

@@ -340,6 +340,7 @@ TREESITTER
• |Query:iter_captures()| supports specifying starting and ending columns.
• |:EditQuery| command gained tab-completion, works with injected languages.
• |LanguageTree:parse()| now accepts a list of ranges.
TUI

View File

@@ -1345,7 +1345,9 @@ LanguageTree:is_valid({exclude_children}, {range})
Parameters: ~
• {exclude_children} (`boolean?`) whether to ignore the validity of
children (default `false`)
• {range} (`Range?`) range to check for validity
• {range} (`Range|Range[]?`) range (or list of ranges,
sorted by starting point in ascending order) to
check for validity
Return: ~
(`boolean`)
@@ -1421,11 +1423,12 @@ LanguageTree:parse({range}, {on_parse}) *LanguageTree:parse()*
if {range} is `true`).
Parameters: ~
• {range} (`boolean|Range?`) Parse this range in the parser's
source. Set to `true` to run a complete parse of the
source (Note: Can be slow!) Set to `false|nil` to only
parse regions with empty ranges (typically only the root
tree without injections).
• {range} (`boolean|Range|Range[]?`) Parse this range (or list of
ranges, sorted by starting point in ascending order) in
the parser's source. Set to `true` to run a complete parse
of the source (Note: Can be slow!) Set to `false|nil` to
only parse regions with empty ranges (typically only the
root tree without injections).
• {on_parse} (`fun(err?: string, trees?: table<integer, TSTree>)?`)
Function invoked when parsing completes. When provided and
`vim.g._ts_force_sync_parsing` is not set, parsing will