mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
feat: allow manage_folds to be a filetype map
This commit is contained in:
parent
26f0320e95
commit
88b5192399
5 changed files with 26 additions and 28 deletions
|
@ -337,6 +337,11 @@ require("aerial").setup({
|
|||
wintypes = "special",
|
||||
},
|
||||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- Set to "auto" to manage folds if your previous foldmethod was 'manual'
|
||||
-- This can be a filetype map (see :help aerial-filetype-map)
|
||||
manage_folds = false,
|
||||
|
||||
-- When you fold code with za, zo, or zc, update the aerial tree as well.
|
||||
-- Only works when manage_folds = true
|
||||
link_folds_to_tree = false,
|
||||
|
@ -345,10 +350,6 @@ require("aerial").setup({
|
|||
-- Only works when manage_folds = true
|
||||
link_tree_to_folds = true,
|
||||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- 'auto' will manage folds if your previous foldmethod was 'manual'
|
||||
manage_folds = false,
|
||||
|
||||
-- Set default symbol icons to use patched font icons (see https://www.nerdfonts.com/)
|
||||
-- "auto" will set it to true if nvim-web-devicons or lspkind-nvim is installed.
|
||||
nerd_font = "auto",
|
||||
|
|
|
@ -177,6 +177,11 @@ OPTIONS *aerial-option
|
|||
wintypes = "special",
|
||||
},
|
||||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- Set to "auto" to manage folds if your previous foldmethod was 'manual'
|
||||
-- This can be a filetype map (see :help aerial-filetype-map)
|
||||
manage_folds = false,
|
||||
|
||||
-- When you fold code with za, zo, or zc, update the aerial tree as well.
|
||||
-- Only works when manage_folds = true
|
||||
link_folds_to_tree = false,
|
||||
|
@ -185,10 +190,6 @@ OPTIONS *aerial-option
|
|||
-- Only works when manage_folds = true
|
||||
link_tree_to_folds = true,
|
||||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- 'auto' will manage folds if your previous foldmethod was 'manual'
|
||||
manage_folds = false,
|
||||
|
||||
-- Set default symbol icons to use patched font icons (see https://www.nerdfonts.com/)
|
||||
-- "auto" will set it to true if nvim-web-devicons or lspkind-nvim is installed.
|
||||
nerd_font = "auto",
|
||||
|
|
|
@ -163,6 +163,11 @@ local default_options = {
|
|||
wintypes = "special",
|
||||
},
|
||||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- Set to "auto" to manage folds if your previous foldmethod was 'manual'
|
||||
-- This can be a filetype map (see :help aerial-filetype-map)
|
||||
manage_folds = false,
|
||||
|
||||
-- When you fold code with za, zo, or zc, update the aerial tree as well.
|
||||
-- Only works when manage_folds = true
|
||||
link_folds_to_tree = false,
|
||||
|
@ -171,10 +176,6 @@ local default_options = {
|
|||
-- Only works when manage_folds = true
|
||||
link_tree_to_folds = true,
|
||||
|
||||
-- Use symbol tree for folding. Set to true or false to enable/disable
|
||||
-- 'auto' will manage folds if your previous foldmethod was 'manual'
|
||||
manage_folds = false,
|
||||
|
||||
-- Set default symbol icons to use patched font icons (see https://www.nerdfonts.com/)
|
||||
-- "auto" will set it to true if nvim-web-devicons or lspkind-nvim is installed.
|
||||
nerd_font = "auto",
|
||||
|
@ -479,12 +480,6 @@ M.setup = function(opts)
|
|||
newconf.use_lspkind = true
|
||||
end
|
||||
|
||||
-- If not managing folds, don't link either direction
|
||||
if newconf.manage_folds == false then
|
||||
newconf.link_tree_to_folds = false
|
||||
newconf.link_folds_to_tree = false
|
||||
end
|
||||
|
||||
-- for backwards compatibility
|
||||
for k, _ in pairs(default_options.lsp) do
|
||||
if newconf[k] ~= nil then
|
||||
|
@ -538,6 +533,7 @@ M.setup = function(opts)
|
|||
for k, v in pairs(newconf) do
|
||||
M[k] = v
|
||||
end
|
||||
M.manage_folds = create_filetype_opt_getter(M.manage_folds, default_options.manage_folds)
|
||||
M.backends = create_filetype_opt_getter(M.backends, default_options.backends)
|
||||
local get_filter_kind_list =
|
||||
create_filetype_opt_getter(M.filter_kind, default_options.filter_kind)
|
||||
|
|
|
@ -20,6 +20,7 @@ local config = require("aerial.config")
|
|||
---@field children? aerial.Symbol[]
|
||||
|
||||
---@class aerial.BufData
|
||||
---@field bufnr integer
|
||||
---@field items aerial.Symbol[]
|
||||
---@field positions any
|
||||
---@field last_win integer
|
||||
|
@ -27,14 +28,18 @@ local config = require("aerial.config")
|
|||
---@field collapse_level integer
|
||||
local BufData = {}
|
||||
|
||||
function BufData.new()
|
||||
---@param bufnr integer
|
||||
function BufData.new(bufnr)
|
||||
local new = {
|
||||
bufnr = bufnr,
|
||||
items = {},
|
||||
positions = {},
|
||||
last_win = -1,
|
||||
collapsed = {},
|
||||
collapse_level = 99,
|
||||
}
|
||||
-- cache the evaluation of managing folds
|
||||
new.manage_folds = config.manage_folds(bufnr)
|
||||
setmetatable(new, { __index = BufData })
|
||||
return new
|
||||
end
|
||||
|
@ -98,7 +103,7 @@ end
|
|||
---@param item aerial.Symbol
|
||||
---@return boolean
|
||||
function BufData:is_collapsable(item)
|
||||
return config.manage_folds or (item.children and not vim.tbl_isempty(item.children))
|
||||
return self.manage_folds or (item.children and not vim.tbl_isempty(item.children))
|
||||
end
|
||||
|
||||
---@generic T
|
||||
|
@ -166,11 +171,6 @@ local buf_to_symbols = {}
|
|||
|
||||
local M = {}
|
||||
|
||||
---@return aerial.BufData
|
||||
function M.create()
|
||||
return BufData.new()
|
||||
end
|
||||
|
||||
---@param buf nil|integer
|
||||
---@return aerial.BufData
|
||||
function M.get_or_create(buf)
|
||||
|
@ -178,7 +178,7 @@ function M.get_or_create(buf)
|
|||
local bufnr, _ = util.get_buffers(buf)
|
||||
local bufdata = buf_to_symbols[bufnr]
|
||||
if not bufdata then
|
||||
bufdata = BufData.new()
|
||||
bufdata = BufData.new(bufnr)
|
||||
if bufnr then
|
||||
buf_to_symbols[bufnr] = bufdata
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ local M = {}
|
|||
---@param bufnr nil|integer
|
||||
M.add_fold_mappings = function(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
if config.link_folds_to_tree then
|
||||
if config.manage_folds(bufnr) and config.link_folds_to_tree then
|
||||
local aerial = require("aerial")
|
||||
local tree = require("aerial.tree")
|
||||
vim.keymap.set("n", "za", tree.toggle, { buffer = bufnr })
|
||||
|
@ -98,7 +98,7 @@ M.restore_foldmethod = function()
|
|||
end
|
||||
|
||||
M.maybe_set_foldmethod = function(bufnr)
|
||||
local manage_folds = config.manage_folds
|
||||
local manage_folds = config.manage_folds(bufnr)
|
||||
if not manage_folds then
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue