diff options
author | Jaehwang Jung <tomtomjhj@gmail.com> | 2023-06-28 03:05:09 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-27 19:05:09 +0100 |
commit | c7e7f1d4b4b62c75bb54e652f25c6c6b8785a7f4 (patch) | |
tree | 4faaaa5698deec86260175df77b7ef775175e2c2 /test/functional/treesitter/parser_spec.lua | |
parent | ab65a98adba4d32b03e7296529c4bf1491c783eb (diff) | |
download | rneovim-c7e7f1d4b4b62c75bb54e652f25c6c6b8785a7f4.tar.gz rneovim-c7e7f1d4b4b62c75bb54e652f25c6c6b8785a7f4.tar.bz2 rneovim-c7e7f1d4b4b62c75bb54e652f25c6c6b8785a7f4.zip |
fix(treesitter): make foldexpr work without highlighting (#24167)
Problem: Treesitter fold is not updated if treesitter hightlight is not
active. More precisely, updating folds requires `LanguageTree:parse()`.
Solution: Call `parse()` before computing folds and compute folds when
lines are added/removed.
This doesn't guarantee correctness of the folds, because some changes
that don't add/remove line won't update the folds even if they should
(e.g. adding pair of braces). But it is good enough for most cases,
while not introducing big overhead.
Also, if highlighting is active, it is likely that
`TSHighlighter._on_buf` already ran `parse()` (or vice versa).
Diffstat (limited to 'test/functional/treesitter/parser_spec.lua')
-rw-r--r-- | test/functional/treesitter/parser_spec.lua | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index e463382d07..d2f40bfe00 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -922,12 +922,6 @@ int x = INT_MAX; [19] = '1' }, get_fold_levels()) helpers.command('1,2d') - helpers.poke_eventloop() - - exec_lua([[vim.treesitter.get_parser():parse()]]) - - helpers.poke_eventloop() - helpers.sleep(100) eq({ [1] = '0', @@ -947,6 +941,29 @@ int x = INT_MAX; [15] = '2', [16] = '1', [17] = '0' }, get_fold_levels()) + + helpers.command('1put!') + + eq({ + [1] = '>1', + [2] = '1', + [3] = '1', + [4] = '1', + [5] = '>2', + [6] = '2', + [7] = '2', + [8] = '1', + [9] = '1', + [10] = '>2', + [11] = '2', + [12] = '2', + [13] = '2', + [14] = '2', + [15] = '>3', + [16] = '3', + [17] = '3', + [18] = '2', + [19] = '1' }, get_fold_levels()) end) it('tracks the root range properly (#22911)', function() |