mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
fix(ts_utils): fix swap_nodes after get_node_text change
After some discussion, it looks like the easiest thing to do for now is to keep a private copy of get_node_text (just to skip the deprecation message) and invoke that, until core provides an equivalent function that can return the node content in a table representing the node "lines". Also fixes the statusline by calling the private version for get_node_text until a change is made in core.
This commit is contained in:
parent
bd2f5d770d
commit
44b7c81002
2 changed files with 35 additions and 32 deletions
|
|
@ -3,7 +3,6 @@ local utils = require "nvim-treesitter.utils"
|
|||
local info = require "nvim-treesitter.info"
|
||||
local configs = require "nvim-treesitter.configs"
|
||||
local parsers = require "nvim-treesitter.parsers"
|
||||
local ts_query = vim.treesitter.query
|
||||
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||
|
||||
-- Registers all query predicates
|
||||
|
|
@ -22,23 +21,6 @@ function M.define_modules(...)
|
|||
configs.define_modules(...)
|
||||
end
|
||||
|
||||
local get_line_for_node = function(node, type_patterns, transform_fn, bufnr)
|
||||
local node_type = node:type()
|
||||
local is_valid = false
|
||||
for _, rgx in ipairs(type_patterns) do
|
||||
if node_type:find(rgx) then
|
||||
is_valid = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not is_valid then
|
||||
return ""
|
||||
end
|
||||
local line = transform_fn(vim.trim(ts_query.get_node_text(node, bufnr) or ""))
|
||||
-- Escape % to avoid statusline to evaluate content as expression
|
||||
return line:gsub("%%", "%%%%")
|
||||
end
|
||||
|
||||
-- Trim spaces and opening brackets from end
|
||||
local transform_line = function(line)
|
||||
return line:gsub("%s*[%[%(%{]*%s*$", "")
|
||||
|
|
@ -67,7 +49,7 @@ function M.statusline(opts)
|
|||
local expr = current_node
|
||||
|
||||
while expr do
|
||||
local line = get_line_for_node(expr, type_patterns, transform_fn, bufnr)
|
||||
local line = ts_utils._get_line_for_node(expr, type_patterns, transform_fn, bufnr)
|
||||
if line ~= "" and not vim.tbl_contains(lines, line) then
|
||||
table.insert(lines, 1, line)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue