commit f40a109716d7f748dd9e9f70b57e4d0bb285518b
parent b3342171d533f3d9dd33bbe5ff09f0d7b007f5a3
Author: Lewis Russell <lewis6991@gmail.com>
Date: Wed, 13 Sep 2023 10:39:34 +0100
fix(treesitter): fix trim predicate
Diffstat:
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
@@ -514,7 +514,10 @@ local directive_handlers = {
-- Example: (#trim! @fold)
-- TODO(clason): generalize to arbitrary whitespace removal
['trim!'] = function(match, _, bufnr, pred, metadata)
- local node = match[pred[2]]
+ local capture_id = pred[2]
+ assert(type(capture_id) == 'number')
+
+ local node = match[capture_id]
if not node then
return
end
@@ -526,9 +529,9 @@ local directive_handlers = {
return
end
- while true do
+ while end_row >= start_row do
-- As we only care when end_col == 0, always inspect one line above end_row.
- local end_line = vim.api.nvim_buf_get_lines(bufnr, end_row - 1, end_row, true)[1]
+ local end_line = api.nvim_buf_get_lines(bufnr, end_row - 1, end_row, true)[1]
if end_line ~= '' then
break
@@ -539,7 +542,8 @@ local directive_handlers = {
-- If this produces an invalid range, we just skip it.
if start_row < end_row or (start_row == end_row and start_col <= end_col) then
- metadata.range = { start_row, start_col, end_row, end_col }
+ metadata[capture_id] = metadata[capture_id] or {}
+ metadata[capture_id].range = { start_row, start_col, end_row, end_col }
end
end,
}