From 44b7c8100269161e20d585f24bce322f6dcdf8d2 Mon Sep 17 00:00:00 2001 From: francisco souza <108725+fsouza@users.noreply.github.com> Date: Thu, 21 Apr 2022 10:23:36 -0400 Subject: 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. --- lua/nvim-treesitter.lua | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'lua/nvim-treesitter.lua') diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index 0165b5383..efdf21e98 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -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 -- cgit v1.2.3-70-g09d2