aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-treesitter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/nvim-treesitter.lua')
-rw-r--r--lua/nvim-treesitter.lua16
1 files changed, 9 insertions, 7 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua
index d4771cea8..0165b5383 100644
--- a/lua/nvim-treesitter.lua
+++ b/lua/nvim-treesitter.lua
@@ -4,6 +4,7 @@ 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
require "nvim-treesitter.query_predicates"
@@ -21,7 +22,7 @@ function M.define_modules(...)
configs.define_modules(...)
end
-local get_line_for_node = function(node, type_patterns, transform_fn)
+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
@@ -33,7 +34,7 @@ local get_line_for_node = function(node, type_patterns, transform_fn)
if not is_valid then
return ""
end
- local line = transform_fn(vim.trim(ts_query.get_node_text(node)[1] or ""))
+ 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
@@ -48,15 +49,16 @@ function M.statusline(opts)
return
end
local options = opts or {}
- if type(opts) == "number" then
- options = { indicator_size = opts }
- end
+ -- if type(opts) == "number" then
+ -- options = { indicator_size = opts }
+ -- end
+ local bufnr = options.bufnr or 0
local indicator_size = options.indicator_size or 100
local type_patterns = options.type_patterns or { "class", "function", "method" }
local transform_fn = options.transform_fn or transform_line
local separator = options.separator or " -> "
- local current_node = ts_query.get_node_at_cursor()
+ local current_node = ts_utils.get_node_at_cursor()
if not current_node then
return ""
end
@@ -65,7 +67,7 @@ function M.statusline(opts)
local expr = current_node
while expr do
- local line = get_line_for_node(expr, type_patterns, transform_fn)
+ local line = 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