diff --git a/lua/lazyvim/plugins/extras/editor/aerial.lua b/lua/lazyvim/plugins/extras/editor/aerial.lua new file mode 100644 index 00000000..2d86d0d0 --- /dev/null +++ b/lua/lazyvim/plugins/extras/editor/aerial.lua @@ -0,0 +1,133 @@ +local Config = require("lazyvim.config") +local Util = require("lazyvim.util") + +return { + { + "stevearc/aerial.nvim", + event = "LazyFile", + opts = function() + ---@diagnostic disable-next-line: no-unknown + local lualine = require("lualine.components.aerial") + + -- Strip trailing spaces from symbols in statusline + ---@param _ any + ---@param symbols {icon?:string}[] + lualine.format_status = Util.inject.args(lualine.format_status, function(_, symbols) + for _, s in ipairs(symbols) do + s.icon = s.icon and s.icon:gsub("%s*$", "") or nil + end + end) + + local icons = vim.deepcopy(Config.icons.kinds) + + -- HACK: fix lua's weird choice for `Package` for control + -- structures like if/else/for/etc. + icons.lua = { Package = icons.Control } + + ---@type table|false + local filter_kind = false + if Config.kind_filter then + filter_kind = assert(vim.deepcopy(Config.kind_filter)) + filter_kind._ = filter_kind.default + filter_kind.default = nil + end + + local opts = { + attach_mode = "global", + backends = { "lsp", "treesitter", "markdown", "man" }, + show_guides = true, + layout = { + resize_to_content = false, + win_opts = { + winhl = "Normal:NormalFloat,FloatBorder:NormalFloat,SignColumn:SignColumnSB", + signcolumn = "yes", + statuscolumn = " ", + }, + }, + icons = icons, + filter_kind = filter_kind, + -- stylua: ignore + guides = { + mid_item = "├╴", + last_item = "└╴", + nested_top = "│ ", + whitespace = " ", + }, + } + return opts + end, + keys = { + { "cs", "SymbolsOutline", desc = "Symbols Outline" }, + }, + }, + + -- Telescope integration + { + "nvim-telescope/telescope.nvim", + opts = function() + Util.on_load("telescope.nvim", function() + require("telescope").load_extension("aerial") + end) + end, + keys = { + { + "ss", + "Telescope aerial", + desc = "Goto Symbol (Aerial)", + }, + }, + }, + + -- edgy integration + { + "folke/edgy.nvim", + optional = true, + opts = function(_, opts) + local edgy_idx = Util.plugin.extra_idx("ui.edgy") + local aerial_idx = Util.plugin.extra_idx("editor.aerial") + + if edgy_idx and edgy_idx > aerial_idx then + Util.warn("The `edgy.nvim` extra must be **imported** before the `aerial.nvim` extra to work properly.", { + title = "LazyVim", + }) + end + + opts.right = opts.right or {} + table.insert(opts.right, { + title = "Aerial", + ft = "aerial", + pinned = true, + open = "AerialOpen", + }) + end, + }, + + -- lualine integration + { + "nvim-lualine/lualine.nvim", + optional = true, + opts = function(_, opts) + table.insert(opts.sections.lualine_c, { + "aerial", + -- The separator to be used to separate symbols in status line. + sep = " ", + + -- The number of symbols to render top-down. In order to render only 'N' last + -- symbols, negative numbers may be supplied. For instance, 'depth = -1' can + -- be used in order to render only current symbol. + depth = 5, + + -- When 'dense' mode is on, icons are not rendered near their symbols. Only + -- a single icon that represents the kind of current symbol is rendered at + -- the beginning of status line. + dense = false, + + -- The separator to be used to separate symbols in dense mode. + dense_sep = ".", + + -- Color the symbol icons. + colored = true, + }) + end, + }, +} diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index 7491ca7d..c022758f 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -27,6 +27,15 @@ function M.setup() M.lazy_file() end +function M.extra_idx(name) + local Config = require("lazy.core.config") + for i, extra in ipairs(Config.spec.modules) do + if extra == "lazyvim.plugins.extras." .. name then + return i + end + end +end + -- Properly load file based plugins without blocking the UI function M.lazy_file() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0