diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-08-10 14:21:56 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2023-08-12 16:11:36 +0100 |
commit | 2ca076e45fb3f1c08f6a1a374834df0701b8d778 (patch) | |
tree | 3338df585168c4e6455137757519ca0bcd211c8c /runtime/doc/treesitter.txt | |
parent | 5a25dcc5a4c73f50902432e32335ab073950cceb (diff) | |
download | rneovim-2ca076e45fb3f1c08f6a1a374834df0701b8d778.tar.gz rneovim-2ca076e45fb3f1c08f6a1a374834df0701b8d778.tar.bz2 rneovim-2ca076e45fb3f1c08f6a1a374834df0701b8d778.zip |
feat(treesitter)!: incremental injection parsing
Problem:
Treesitter highlighting is slow for large files with lots of injections.
Solution:
Only parse injections we are going to render during a redraw cycle.
---
- `LanguageTree:parse()` will no longer parse injections by default and
now requires an explicit range argument to be passed.
- `TSHighlighter` now parses injections incrementally during on_win
callbacks for the line range being rendered.
- Plugins which require certain injections to be parsed must run
`parser:parse({ start_row, end_row })` before using the tree.
Diffstat (limited to 'runtime/doc/treesitter.txt')
-rw-r--r-- | runtime/doc/treesitter.txt | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 13c0bd024a..f3e697807f 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -1020,13 +1020,6 @@ set({lang}, {query_name}, {text}) *vim.treesitter.query.set()* ============================================================================== -Lua module: vim.treesitter.highlighter *lua-treesitter-highlighter* - -TSHighlighter:destroy() *TSHighlighter:destroy()* - Removes all internal references to the highlighter. - - -============================================================================== Lua module: vim.treesitter.languagetree *lua-treesitter-languagetree* @@ -1053,7 +1046,7 @@ Whenever you need to access the current syntax tree, parse the buffer: >lua - local tree = parser:parse() + local tree = parser:parse({ start_row, end_row }) < @@ -1112,7 +1105,7 @@ LanguageTree:included_regions() *LanguageTree:included_regions()* Gets the set of included regions Return: ~ - integer[][] + Range6[][] LanguageTree:invalidate({reload}) *LanguageTree:invalidate()* Invalidates this parser and all its children @@ -1155,10 +1148,22 @@ LanguageTree:named_node_for_range({range}, {opts}) Return: ~ |TSNode| | nil Found node -LanguageTree:parse() *LanguageTree:parse()* - Parses all defined regions using a treesitter parser for the language this - tree represents. This will run the injection query for this language to - determine if any child languages should be created. +LanguageTree:parse({range}) *LanguageTree:parse()* + Recursively parse all regions in the language tree using + |treesitter-parsers| for the corresponding languages and run injection + queries on the parsed trees to determine whether child trees should be + created and parsed. + + Any region with empty range (`{}`, typically only the root tree) is always + parsed; otherwise (typically injections) only if it intersects {range} (or + if {range} is `true`). + + Parameters: ~ + • {range} boolean|Range|nil: 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). Return: ~ TSTree[] |