mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
fix(predicates): remove upstreamed predicates and directives
Problem: Overriding upstreamed predicates replaces optimized versions on Nvim 0.11. Solution: Now that nvim-treesitter requires Nvim 0.10, simply remove the upstreamed predicates and directives.
This commit is contained in:
parent
cfc6f2c117
commit
9210b9a4fa
1 changed files with 0 additions and 74 deletions
|
|
@ -62,42 +62,6 @@ query.add_predicate("nth?", function(match, _pattern, _bufnr, pred)
|
|||
return false
|
||||
end, opts)
|
||||
|
||||
---@param match (TSNode|nil)[]
|
||||
---@param _pattern string
|
||||
---@param _bufnr integer
|
||||
---@param pred string[]
|
||||
---@return boolean|nil
|
||||
local function has_ancestor(match, _pattern, _bufnr, pred)
|
||||
if not valid_args(pred[1], pred, 2) then
|
||||
return
|
||||
end
|
||||
|
||||
local node = match[pred[2]]
|
||||
local ancestor_types = { unpack(pred, 3) }
|
||||
if not node then
|
||||
return true
|
||||
end
|
||||
|
||||
local just_direct_parent = pred[1]:find("has-parent", 1, true)
|
||||
|
||||
node = node:parent()
|
||||
while node do
|
||||
if vim.tbl_contains(ancestor_types, node:type()) then
|
||||
return true
|
||||
end
|
||||
if just_direct_parent then
|
||||
node = nil
|
||||
else
|
||||
node = node:parent()
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
query.add_predicate("has-ancestor?", has_ancestor, opts)
|
||||
|
||||
query.add_predicate("has-parent?", has_ancestor, opts)
|
||||
|
||||
---@param match (TSNode|nil)[]
|
||||
---@param _pattern string
|
||||
---@param bufnr integer
|
||||
|
|
@ -201,41 +165,3 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
|||
end
|
||||
metadata[id].text = string.lower(text)
|
||||
end, opts)
|
||||
|
||||
-- Trim blank lines from end of the region
|
||||
-- Arguments are the captures to trim.
|
||||
---@param match (TSNode|nil)[]
|
||||
---@param _ string
|
||||
---@param bufnr integer
|
||||
---@param pred string[]
|
||||
---@param metadata table
|
||||
query.add_directive("trim!", function(match, _, bufnr, pred, metadata)
|
||||
for _, id in ipairs { select(2, unpack(pred)) } do
|
||||
local node = match[id]
|
||||
local start_row, start_col, end_row, end_col = node:range()
|
||||
|
||||
-- Don't trim if region ends in middle of a line
|
||||
if end_col ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
while true 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]
|
||||
|
||||
if end_line ~= "" then
|
||||
break
|
||||
end
|
||||
|
||||
end_row = end_row - 1
|
||||
end
|
||||
|
||||
-- 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 not metadata[id] then
|
||||
metadata[id] = {}
|
||||
end
|
||||
metadata[id].range = { start_row, start_col, end_row, end_col }
|
||||
end
|
||||
end
|
||||
end, opts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue