From 7bfd9157fec018f86fc83b2be4c01b489cf8cdf5 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 17 Jun 2022 19:36:21 +1000 Subject: [PATCH] update TS fold --- lua/navigator/foldts.lua | 7 +++---- lua/navigator/treesitter.lua | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/navigator/foldts.lua b/lua/navigator/foldts.lua index 01ad9a9..42c2732 100644 --- a/lua/navigator/foldts.lua +++ b/lua/navigator/foldts.lua @@ -17,15 +17,14 @@ function M.on_attach() -- M.update_folds() end -function Custom_fold_text() +function NG_custom_fold_text() local line = vim.fn.getline(vim.v.foldstart) local line_count = vim.v.foldend - vim.v.foldstart + 1 -- log("" .. line .. " // " .. line_count .. " lines") return ' ⚡' .. line .. ': ' .. line_count .. ' lines' end -vim.opt.foldtext = Custom_fold_text() - +vim.opt.foldtext = NG_custom_fold_text() vim.opt.fillchars = { eob = '-', fold = ' ' } vim.opt.viewoptions:remove('options') @@ -39,7 +38,7 @@ function M.setup_fold() api.nvim_command('augroup FoldingCommand') api.nvim_command('autocmd! * ') api.nvim_command('augroup end') - vim.opt.foldtext = 'v:lua.custom_fold_text()' + vim.opt.foldtext = 'v:lua.NG_custom_fold_text()' vim.opt.fillchars = { eob = '-', fold = ' ' } vim.opt.viewoptions:remove('options') diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index 4af6409..5179570 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -423,6 +423,10 @@ local function get_all_nodes(bufnr, filter, summary) indent = string.rep(' ', #parents - 1) .. ' ' end item.indent = indent + item.indent_level = #parents + if #all_nodes >= 1 then + all_nodes[#all_nodes].next_indent_level = #parents + end item.text = string.format(' %s %s%-10s\t %s', item.kind, indent, item.node_text, item.full_text) if #item.text > length then