diff --git a/lua/lazyvim/util/extras.lua b/lua/lazyvim/util/extras.lua index 74ab4b4c..410466d9 100644 --- a/lua/lazyvim/util/extras.lua +++ b/lua/lazyvim/util/extras.lua @@ -16,12 +16,15 @@ local Text = require("lazy.view.text") ---@field desc? string ---@field enabled boolean ---@field managed boolean +---@field recommended? boolean ---@field row? number +---@field section? string ---@field plugins string[] ---@field optional string[] ---@class lazyvim.util.extras local M = {} +M.buf = 0 ---@type LazyExtraSource[] M.sources = { @@ -33,6 +36,24 @@ M.ns = vim.api.nvim_create_namespace("lazyvim.extras") ---@type string[] M.state = nil +---@param opts {ft?: string|string[], root?: string|string[]} +---@return boolean +function M.wants(opts) + if opts.ft then + opts.ft = type(opts.ft) == "string" and { opts.ft } or opts.ft + for _, f in ipairs(opts.ft) do + if vim.bo[M.buf].filetype == f then + return true + end + end + end + if opts.root then + opts.root = type(opts.root) == "string" and { opts.root } or opts.root + return #LazyVim.root.detectors.pattern(M.buf, opts.root) > 0 + end + return false +end + ---@return LazyExtra[] function M.get() M.state = M.state or LazyConfig.spec.modules @@ -74,6 +95,12 @@ function M.get_extra(source, modname) table.sort(plugins) table.sort(optional) + ---@type boolean|(fun():boolean?)|nil + local recommended = require(modname).recommended or false + if type(recommended) == "function" then + recommended = recommended() or false + end + ---@type LazyExtra return { source = source, @@ -81,6 +108,7 @@ function M.get_extra(source, modname) module = modname, enabled = enabled, desc = require(modname).desc, + recommended = recommended, managed = vim.tbl_contains(Config.json.data.extras, modname) or not enabled, plugins = plugins, optional = optional, @@ -97,6 +125,7 @@ local X = {} ---@return LazyExtraView function X.new() local self = setmetatable({}, { __index = X }) + M.buf = vim.api.nvim_get_current_buf() self.float = Float.new({ title = "LazyVim Extras" }) self.float:on_key("x", function() self:toggle() @@ -186,8 +215,14 @@ function X:render() :append("", "LazySpecial") :append(" key", "LazyComment") :nl() + for _, extra in ipairs(self.extras) do + extra.section = nil + end self:section({ enabled = true, title = "Enabled" }) - self:section({ enabled = false, title = "Disabled" }) + self:section({ recommended = true, filter = "^lang%.", title = "Recommended Languages", empty = false }) + self:section({ recommended = true, title = "Recommended Plugins", empty = false }) + self:section({ title = "Languages", filter = "^lang%." }) + self:section({ title = "Plugins" }) end ---@param extra LazyExtra @@ -206,6 +241,9 @@ function X:extra(extra) self.text:append(" " .. LazyConfig.options.ui.icons.not_loaded .. " ", hl) end self.text:append(extra.name) + if extra.recommended then + self.text:append(" "):append(LazyConfig.options.ui.icons.favorite or " ", "LazyCommit") + end if extra.source.name ~= "LazyVim" then self.text:append(" "):append(LazyConfig.options.ui.icons.event .. " " .. extra.source.name, "LazyReasonEvent") end @@ -221,16 +259,24 @@ function X:extra(extra) self.text:nl() end ----@param opts {enabled?:boolean, title?:string} +---@param opts {enabled?:boolean, title:string, recommended?:boolean, filter?:string, empty?:boolean} function X:section(opts) opts = opts or {} ---@type LazyExtra[] local extras = vim.tbl_filter(function(extra) - return opts.enabled == nil or extra.enabled == opts.enabled + return extra.section == nil + and (opts.enabled == nil or extra.enabled == opts.enabled) + and (opts.recommended == nil or extra.recommended == opts.recommended) + and (opts.filter == nil or extra.name:find(opts.filter)) end, self.extras) + if opts.empty == false and #extras == 0 then + return + end + self.text:nl():append(opts.title .. ":", "LazyH2"):append(" (" .. #extras .. ")", "LazyComment"):nl() for _, extra in ipairs(extras) do + extra.section = opts.title self:extra(extra) end end