mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
fix(treesitter): fix trim predicate
This commit is contained in:

committed by
Lewis Russell

parent
b3342171d5
commit
f40a109716
@@ -514,7 +514,10 @@ local directive_handlers = {
|
|||||||
-- Example: (#trim! @fold)
|
-- Example: (#trim! @fold)
|
||||||
-- TODO(clason): generalize to arbitrary whitespace removal
|
-- TODO(clason): generalize to arbitrary whitespace removal
|
||||||
['trim!'] = function(match, _, bufnr, pred, metadata)
|
['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
|
if not node then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -526,9 +529,9 @@ local directive_handlers = {
|
|||||||
return
|
return
|
||||||
end
|
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.
|
-- 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
|
if end_line ~= '' then
|
||||||
break
|
break
|
||||||
@@ -539,7 +542,8 @@ local directive_handlers = {
|
|||||||
|
|
||||||
-- If this produces an invalid range, we just skip it.
|
-- 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
|
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
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user