2021-07-04 16:12:17 -05:00
|
|
|
local install = require "nvim-treesitter.install"
|
|
|
|
|
local utils = require "nvim-treesitter.utils"
|
|
|
|
|
local info = require "nvim-treesitter.info"
|
|
|
|
|
local configs = require "nvim-treesitter.configs"
|
|
|
|
|
local parsers = require "nvim-treesitter.parsers"
|
2022-04-18 17:28:40 +02:00
|
|
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
2020-09-01 23:39:06 +02:00
|
|
|
|
2020-08-15 09:24:24 -05:00
|
|
|
-- Registers all query predicates
|
2021-07-04 16:12:17 -05:00
|
|
|
require "nvim-treesitter.query_predicates"
|
2020-08-15 09:24:24 -05:00
|
|
|
|
2020-04-18 19:32:51 +02:00
|
|
|
local M = {}
|
|
|
|
|
|
2020-05-08 11:22:59 +02:00
|
|
|
function M.setup()
|
2021-07-04 16:12:17 -05:00
|
|
|
utils.setup_commands("install", install.commands)
|
|
|
|
|
utils.setup_commands("info", info.commands)
|
|
|
|
|
utils.setup_commands("configs", configs.commands)
|
2020-07-02 10:26:53 -05:00
|
|
|
configs.init()
|
|
|
|
|
end
|
2020-04-18 19:32:51 +02:00
|
|
|
|
2020-07-02 10:26:53 -05:00
|
|
|
function M.define_modules(...)
|
|
|
|
|
configs.define_modules(...)
|
2020-04-21 23:40:23 +02:00
|
|
|
end
|
2020-04-19 14:43:55 +02:00
|
|
|
|
2020-10-09 13:43:34 +02:00
|
|
|
-- Trim spaces and opening brackets from end
|
|
|
|
|
local transform_line = function(line)
|
2021-07-04 16:12:17 -05:00
|
|
|
return line:gsub("%s*[%[%(%{]*%s*$", "")
|
2020-10-09 13:43:34 +02:00
|
|
|
end
|
|
|
|
|
|
2020-10-09 19:08:44 +02:00
|
|
|
function M.statusline(opts)
|
2021-07-04 16:12:17 -05:00
|
|
|
if not parsers.has_parser() then
|
|
|
|
|
return
|
|
|
|
|
end
|
2020-10-09 13:43:34 +02:00
|
|
|
local options = opts or {}
|
2022-04-18 17:28:40 +02:00
|
|
|
-- if type(opts) == "number" then
|
|
|
|
|
-- options = { indicator_size = opts }
|
|
|
|
|
-- end
|
|
|
|
|
local bufnr = options.bufnr or 0
|
2020-10-09 13:43:34 +02:00
|
|
|
local indicator_size = options.indicator_size or 100
|
2021-07-04 16:12:17 -05:00
|
|
|
local type_patterns = options.type_patterns or { "class", "function", "method" }
|
2020-10-09 13:43:34 +02:00
|
|
|
local transform_fn = options.transform_fn or transform_line
|
2021-07-04 16:12:17 -05:00
|
|
|
local separator = options.separator or " -> "
|
2020-10-09 13:43:34 +02:00
|
|
|
|
2022-04-18 17:28:40 +02:00
|
|
|
local current_node = ts_utils.get_node_at_cursor()
|
2021-07-04 16:12:17 -05:00
|
|
|
if not current_node then
|
|
|
|
|
return ""
|
|
|
|
|
end
|
2020-10-09 13:43:34 +02:00
|
|
|
|
|
|
|
|
local lines = {}
|
|
|
|
|
local expr = current_node
|
|
|
|
|
|
|
|
|
|
while expr do
|
2022-04-21 10:23:36 -04:00
|
|
|
local line = ts_utils._get_line_for_node(expr, type_patterns, transform_fn, bufnr)
|
2021-07-04 16:12:17 -05:00
|
|
|
if line ~= "" and not vim.tbl_contains(lines, line) then
|
2020-10-09 13:43:34 +02:00
|
|
|
table.insert(lines, 1, line)
|
|
|
|
|
end
|
|
|
|
|
expr = expr:parent()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local text = table.concat(lines, separator)
|
|
|
|
|
local text_len = #text
|
|
|
|
|
if text_len > indicator_size then
|
2021-07-04 16:12:17 -05:00
|
|
|
return "..." .. text:sub(text_len - indicator_size, text_len)
|
2020-10-09 13:43:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-18 19:32:51 +02:00
|
|
|
return M
|