From ecc76eb087af9b00cb02733fcd0b871a9af113e8 Mon Sep 17 00:00:00 2001 From: Nir Tzachar Date: Tue, 19 Apr 2022 17:09:37 +0300 Subject: [PATCH 1/2] adapt to vim.treesitter.query.get_node_text --- lua/nvim-treesitter-refactor/navigation.lua | 5 +++-- lua/nvim-treesitter-refactor/smart_rename.lua | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/nvim-treesitter-refactor/navigation.lua b/lua/nvim-treesitter-refactor/navigation.lua index f0ca5d6..42712db 100644 --- a/lua/nvim-treesitter-refactor/navigation.lua +++ b/lua/nvim-treesitter-refactor/navigation.lua @@ -4,6 +4,7 @@ local ts_utils = require "nvim-treesitter.ts_utils" local utils = require "nvim-treesitter.utils" local locals = require "nvim-treesitter.locals" local configs = require "nvim-treesitter.configs" +local ts_query = vim.treesitter.query local api = vim.api local M = {} @@ -70,7 +71,7 @@ function M.list_definitions(bufnr) for _, node in ipairs(definitions) do local lnum, col, _ = node.node:start() local type = string.upper(node.type:sub(1, 1)) - local text = ts_utils.get_node_text(node.node)[1] or "" + local text = ts_query.get_node_text(node.node) or "" table.insert(qf_list, { bufnr = bufnr, lnum = lnum + 1, @@ -125,7 +126,7 @@ function M.list_definitions_toc() local lnum, col, _ = def.node:start() local type = string.upper(def.type:sub(1, 1)) - local text = ts_utils.get_node_text(def.node)[1] or "" + local text = ts_query.get_node_text(def.node) or "" table.insert(loc_list, { bufnr = bufnr, lnum = lnum + 1, diff --git a/lua/nvim-treesitter-refactor/smart_rename.lua b/lua/nvim-treesitter-refactor/smart_rename.lua index 7740c54..80b3ab8 100644 --- a/lua/nvim-treesitter-refactor/smart_rename.lua +++ b/lua/nvim-treesitter-refactor/smart_rename.lua @@ -5,6 +5,7 @@ local ts_utils = require "nvim-treesitter.ts_utils" local locals = require "nvim-treesitter.locals" local configs = require "nvim-treesitter.configs" local utils = require "nvim-treesitter.utils" +local ts_query = vim.treesitter.query local api = vim.api local M = {} @@ -42,7 +43,7 @@ function M.smart_rename(bufnr) return end - local node_text = ts_utils.get_node_text(node_at_point)[1] + local node_text = ts_query.get_node_text(node_at_point) local input = { prompt = "New name: ", default = node_text or "" } if not vim.ui.input then local new_name = vim.fn.input(input.prompt, input.default) From 3afb083c4d7715b9fb0eaacef563d661a492f79b Mon Sep 17 00:00:00 2001 From: Nir Tzachar Date: Tue, 19 Apr 2022 18:01:24 +0300 Subject: [PATCH 2/2] add bufnr to ts_query.get_node_text --- lua/nvim-treesitter-refactor/navigation.lua | 4 ++-- lua/nvim-treesitter-refactor/smart_rename.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/nvim-treesitter-refactor/navigation.lua b/lua/nvim-treesitter-refactor/navigation.lua index 42712db..6003310 100644 --- a/lua/nvim-treesitter-refactor/navigation.lua +++ b/lua/nvim-treesitter-refactor/navigation.lua @@ -71,7 +71,7 @@ function M.list_definitions(bufnr) for _, node in ipairs(definitions) do local lnum, col, _ = node.node:start() local type = string.upper(node.type:sub(1, 1)) - local text = ts_query.get_node_text(node.node) or "" + local text = ts_query.get_node_text(node.node, bufnr) or "" table.insert(qf_list, { bufnr = bufnr, lnum = lnum + 1, @@ -126,7 +126,7 @@ function M.list_definitions_toc() local lnum, col, _ = def.node:start() local type = string.upper(def.type:sub(1, 1)) - local text = ts_query.get_node_text(def.node) or "" + local text = ts_query.get_node_text(def.node, bufnr) or "" table.insert(loc_list, { bufnr = bufnr, lnum = lnum + 1, diff --git a/lua/nvim-treesitter-refactor/smart_rename.lua b/lua/nvim-treesitter-refactor/smart_rename.lua index 80b3ab8..b5053ed 100644 --- a/lua/nvim-treesitter-refactor/smart_rename.lua +++ b/lua/nvim-treesitter-refactor/smart_rename.lua @@ -43,7 +43,7 @@ function M.smart_rename(bufnr) return end - local node_text = ts_query.get_node_text(node_at_point) + local node_text = ts_query.get_node_text(node_at_point, bufnr) local input = { prompt = "New name: ", default = node_text or "" } if not vim.ui.input then local new_name = vim.fn.input(input.prompt, input.default)