docs: generate docs for commands

This commit is contained in:
Folke Lemaitre 2022-12-18 11:42:54 +01:00
parent f25f942eb7
commit 1730661ec2
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
4 changed files with 72 additions and 17 deletions

View File

@ -277,6 +277,28 @@ return {
## 🚀 Usage ## 🚀 Usage
You can manage all your plugins with the main `:Lazy` command.
Alternatively you can start any operation with a specific command, sub command or API function:
<!-- commands:start -->
| Command | Lua | Key Mapping | Description |
| --------------------------------- | --------------------------- | ----------- | ------------------------------------------------------ |
| `:Lazy home` or `:LazyHome` | `require("lazy").home()` | `<H>` | Go back to plugin list |
| `:Lazy install` or `:LazyInstall` | `require("lazy").install()` | `<I>` | Install missing plugins |
| `:Lazy update` or `:LazyUpdate` | `require("lazy").update()` | `<U>` | Update all plugins. This will also update the lockfile |
| `:Lazy sync` or `:LazySync` | `require("lazy").sync()` | `<S>` | Run install, clean and update |
| `:Lazy clean` or `:LazyClean` | `require("lazy").clean()` | `<X>` | Clean plugins that are no longer needed |
| `:Lazy check` or `:LazyCheck` | `require("lazy").check()` | `<C>` | Check for updates and show the log (git fetch) |
| `:Lazy log` or `:LazyLog` | `require("lazy").log()` | `<L>` | Show recent updates for all plugins |
| `:Lazy restore` or `:LazyRestore` | `require("lazy").restore()` | `<R>` | Updates all plugins to the state in the lockfile |
| `:Lazy profile` or `:LazyProfile` | `require("lazy").profile()` | `<P>` | Show detailed profiling |
| `:Lazy debug` or `:LazyDebug` | `require("lazy").debug()` | `<D>` | Show debug information |
| `:Lazy help` or `:LazyHelp` | `require("lazy").help()` | `<?>` | Toggle this help page |
| `:Lazy clear` or `:LazyClear` | `require("lazy").clear()` | | Clear finished tasks |
<!-- commands:end -->
## 📊 Profiler ## 📊 Profiler
The profiling view shows you why and how long it took to load your plugins. The profiling view shows you why and how long it took to load your plugins.

View File

@ -57,7 +57,7 @@ function M.save(contents)
if not readme:find(pattern) then if not readme:find(pattern) then
error("tag " .. tag .. " not found") error("tag " .. tag .. " not found")
end end
if tag == "toc" then if tag == "toc" or tag == "commands" then
readme = readme:gsub(pattern, "%1\n\n" .. content .. "\n\n%2") readme = readme:gsub(pattern, "%1\n\n" .. content .. "\n\n%2")
else else
readme = readme:gsub(pattern, "%1\n\n```lua\n" .. content .. "\n```\n\n%2") readme = readme:gsub(pattern, "%1\n\n```lua\n" .. content .. "\n```\n\n%2")
@ -73,6 +73,32 @@ function M.extract(file, pattern)
return assert(init:match(pattern)) return assert(init:match(pattern))
end end
function M.commands()
local commands = require("lazy.view.commands").commands
local modes = require("lazy.view").modes
local lines = {
{ "Command", "Lua", "Key Mapping", "Description" },
{ "---", "---", "---", "---" },
}
for _, mode in ipairs(modes) do
if not mode.plugin and commands[mode.name] then
lines[#lines + 1] = {
("`:Lazy %s`"):format(mode.name) .. " or " .. ("`:Lazy%s`"):format(
mode.name:sub(1, 1):upper() .. mode.name:sub(2)
),
([[`require("lazy").%s()`]]):format(mode.name),
mode.key and ("`<%s>`"):format(mode.key) or "",
mode.desc,
}
end
end
local ret = {}
for _, line in ipairs(lines) do
ret[#ret + 1] = "| " .. table.concat(line, " | ") .. " |"
end
return table.concat(ret, "\n")
end
function M.update() function M.update()
local cache_config = M.extract("lua/lazy/core/cache.lua", "\nM%.config = ({.-\n})") local cache_config = M.extract("lua/lazy/core/cache.lua", "\nM%.config = ({.-\n})")
local config = M.extract("lua/lazy/core/config.lua", "\nM%.defaults = ({.-\n})") local config = M.extract("lua/lazy/core/config.lua", "\nM%.defaults = ({.-\n})")
@ -85,6 +111,7 @@ function M.update()
bootstrap = M.extract("lua/lazy/init.lua", "function M%.bootstrap%(%)\n(.-)\nend"), bootstrap = M.extract("lua/lazy/init.lua", "function M%.bootstrap%(%)\n(.-)\nend"),
config = config, config = config,
spec = Util.read_file("lua/lazy/example.lua"), spec = Util.read_file("lua/lazy/example.lua"),
commands = M.commands(),
}) })
vim.cmd.checktime() vim.cmd.checktime()
end end

View File

@ -16,6 +16,7 @@ M.modes = {
{ name = "profile", key = "P", desc = "Show detailed profiling", toggle = true }, { name = "profile", key = "P", desc = "Show detailed profiling", toggle = true },
{ name = "debug", key = "D", desc = "Show debug information", toggle = true }, { name = "debug", key = "D", desc = "Show debug information", toggle = true },
{ name = "help", key = "?", desc = "Toggle this help page", toggle = true }, { name = "help", key = "?", desc = "Toggle this help page", toggle = true },
{ name = "clear", desc = "Clear finished tasks", hide = true },
{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" }, { plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
{ {
@ -163,21 +164,23 @@ function M.show(mode)
}) })
for _, m in ipairs(M.modes) do for _, m in ipairs(M.modes) do
vim.keymap.set("n", m.key, function() if m.key then
local Commands = require("lazy.view.commands") vim.keymap.set("n", m.key, function()
if m.plugin then local Commands = require("lazy.view.commands")
local plugin = get_plugin() if m.plugin then
if plugin then local plugin = get_plugin()
Commands.cmd(m.name, { plugin }) if plugin then
Commands.cmd(m.name, { plugin })
end
else
if M.mode == m.name and m.toggle then
M.mode = nil
return update()
end
Commands.cmd(m.name)
end end
else end, { buffer = buf })
if M.mode == m.name and m.toggle then end
M.mode = nil
return update()
end
Commands.cmd(m.name)
end
end, { buffer = buf })
end end
vim.api.nvim_create_autocmd("User", { vim.api.nvim_create_autocmd("User", {

View File

@ -150,8 +150,11 @@ function M:help()
for _, mode in ipairs(View.modes) do for _, mode in ipairs(View.modes) do
local title = mode.name:sub(1, 1):upper() .. mode.name:sub(2) local title = mode.name:sub(1, 1):upper() .. mode.name:sub(2)
self:append("- ", "LazySpecial", { indent = 2 }) self:append("- ", "LazySpecial", { indent = 2 })
self:append(title, "Title"):append(" <" .. mode.key .. "> ", "LazyKey") self:append(title, "Title")
self:append(mode.desc or ""):nl() if mode.key then
self:append(" <" .. mode.key .. ">", "LazyKey")
end
self:append(" " .. (mode.desc or "")):nl()
end end
end end