aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/parser_spec.lua
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-12-07 03:01:59 -0800
committerGitHub <noreply@github.com>2024-12-07 03:01:59 -0800
commitc63e49cce2d20cee129a6312319dde8dcea6e3f6 (patch)
tree34e35eb3626fff0aa4f0d101d4f4828c531c357c /test/functional/treesitter/parser_spec.lua
parent5c245ec3e95570e515c1665a2ec694828706ac52 (diff)
downloadrneovim-c63e49cce2d20cee129a6312319dde8dcea6e3f6.tar.gz
rneovim-c63e49cce2d20cee129a6312319dde8dcea6e3f6.tar.bz2
rneovim-c63e49cce2d20cee129a6312319dde8dcea6e3f6.zip
fix(treesitter): #trim! range for nodes ending at col 0 #31488
Problem: char-wise folding for `#trim!` ranges are improperly calculated for nodes that end at column 0, due to the way `get_node_text` works. Solution: Add the blank line that `get_node_text` removes for for nodes ending at column 0. Also properly set column positions when performing linewise trims.
Diffstat (limited to 'test/functional/treesitter/parser_spec.lua')
-rw-r--r--test/functional/treesitter/parser_spec.lua35
1 files changed, 31 insertions, 4 deletions
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua
index 8a552c7d34..2f80cee226 100644
--- a/test/functional/treesitter/parser_spec.lua
+++ b/test/functional/treesitter/parser_spec.lua
@@ -696,14 +696,14 @@ print()
end)
it('trims only empty lines by default (backwards compatible)', function()
- insert [[
+ insert(dedent [[
## Heading
With some text
## And another
- With some more]]
+ With some more here]])
local query_text = [[
; query
@@ -716,8 +716,35 @@ print()
end)
eq({
- { 'fold', { 0, 0, 3, 0 } },
- { 'fold', { 4, 0, 7, 0 } },
+ { 'fold', { 0, 0, 2, 14 } },
+ { 'fold', { 4, 0, 6, 19 } },
+ }, run_query('markdown', query_text))
+ end)
+
+ it('can trim lines', function()
+ insert(dedent [[
+ - Fold list
+ - Fold list
+ - Fold list
+ - Fold list
+ - Fold list
+ - Fold list
+ ]])
+
+ local query_text = [[
+ ; query
+ ((list_item
+ (list)) @fold
+ (#trim! @fold 1 1 1 1))
+ ]]
+
+ exec_lua(function()
+ vim.treesitter.start(0, 'markdown')
+ end)
+
+ eq({
+ { 'fold', { 0, 0, 4, 13 } },
+ { 'fold', { 1, 2, 3, 15 } },
}, run_query('markdown', query_text))
end)
end)