[Feature] API for querying plugin status
mrcjkb opened this issue Ā· comments
It says a UI is non-goal for this plugin. Maybe a separate extension plugin for it. But for now, to help debug a config, perhaps an API that can give a list of all plugins managed by lz.n
and full spec of each plugin plus an is_loaded
boolean?
Originally posted by @pseudoparenchymatous in #18
This could be implemented as a handler + using require('lz.n.state')
Whenever a plugin is loaded, del gets called. Simply have the handler keep an internal state of the plugin names that were called, and a function to require('lz.n.state') and zip in a is_loaded field into the ones that were loaded already when it returns the list.
Probably only like 50 lines or so. Should it be added to the plugin or should it just be posted in discussions?
Kinda quick and dirty but this works:
---@type table<string, string>
local states = {}
local M = {
---@type lz.n.Handler
handler = {
-- this field does nothing but it does stop others from using is_loaded,
-- which is good because we overwrite the value in getAllPlugins
spec_field = "is_loaded",
---@param plugin lz.n.Plugin
del = function (plugin)
states[plugin.name] = plugin.name
end,
add = function(_) end,
},
}
function M.get_all_plugins()
local result = vim.deepcopy(require("lz.n.state").plugins)
for _, name in pairs(states) do
if result[name] ~= nil then
---@diagnostic disable-next-line: inject-field
result[name].is_loaded = true
end
end
return result
end
function M.get_a_plugin(name)
local result = vim.deepcopy(require("lz.n.state").plugins[name])
if result ~= nil and states[name] ~= nil then
---@diagnostic disable-next-line: inject-field
result.is_loaded = true
end
return result
end
return M
Simply add require('lz.n').register_handler(require('the.file').handler)
to the start of your config
and then you can call :lua print(vim.inspect(require('the.file').get_all_plugins()))
and it will print out all the specs and whether they were loaded or not or you can :lua print(vim.inspect(require('the.file').get_a_plugin("apluginname")))
for just 1