feat: added `:Lazy load foobar.nvim` to load a plugin

This commit is contained in:
Folke Lemaitre 2022-12-19 14:19:10 +01:00
parent 8a0da3b27e
commit 2dd6230018
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
4 changed files with 52 additions and 21 deletions

View File

@ -290,7 +290,7 @@ return {
performance = {
cache = {
enabled = true,
path = vim.fn.stdpath("state") .. "/lazy.state",
path = vim.fn.stdpath("state") .. "/lazy/cache",
-- Once one of the following events triggers, caching will be disabled.
-- To cache all modules, set this to `{}`, but that is not recommended.
-- The default is to disable on:
@ -335,20 +335,21 @@ Alternatively you can start any operation with a specific command, sub command o
<!-- 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 |
| Command | Lua | Key Mapping | Description |
| --------------- | --------------------------- | ----------- | --------------------------------------------------------------------------------------------- |
| `:Lazy home` | `require("lazy").home()` | `<H>` | Go back to plugin list |
| `:Lazy install` | `require("lazy").install()` | `<I>` | Install missing plugins |
| `:Lazy update` | `require("lazy").update()` | `<U>` | Update all plugins. This will also update the lockfile |
| `:Lazy sync` | `require("lazy").sync()` | `<S>` | Run install, clean and update |
| `:Lazy clean` | `require("lazy").clean()` | `<X>` | Clean plugins that are no longer needed |
| `:Lazy check` | `require("lazy").check()` | `<C>` | Check for updates and show the log (git fetch) |
| `:Lazy log` | `require("lazy").log()` | `<L>` | Show recent updates for all plugins |
| `:Lazy restore` | `require("lazy").restore()` | `<R>` | Updates all plugins to the state in the lockfile |
| `:Lazy profile` | `require("lazy").profile()` | `<P>` | Show detailed profiling |
| `:Lazy debug` | `require("lazy").debug()` | `<D>` | Show debug information |
| `:Lazy help` | `require("lazy").help()` | `<?>` | Toggle this help page |
| `:Lazy clear` | `require("lazy").clear()` | | Clear finished tasks |
| `:Lazy load` | `require("lazy").load()` | | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim` |
<!-- commands:end -->

View File

@ -83,9 +83,7 @@ function M.commands()
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)
),
("`:Lazy %s`"):format(mode.name),
([[`require("lazy").%s()`]]):format(mode.name),
mode.key and ("`<%s>`"):format(mode.key) or "",
mode.desc,

View File

@ -1,6 +1,7 @@
local View = require("lazy.view")
local Manage = require("lazy.manage")
local Util = require("lazy.util")
local Config = require("lazy.core.config")
local M = {}
@ -60,20 +61,46 @@ M.commands = {
restore = function(plugins)
Manage.update({ clear = true, lockfile = true, mode = "restore", plugins = plugins })
end,
load = function(plugins)
require("lazy.core.loader").load(plugins, { cmd = "LazyLoad" })
end,
}
function M.complete_unloaded(prefix)
local plugins = {}
for name, plugin in pairs(Config.plugins) do
if not plugin._.loaded then
plugins[#plugins + 1] = name
end
end
table.sort(plugins)
---@param key string
return vim.tbl_filter(function(key)
return key:find(prefix) == 1
end, plugins)
end
function M.setup()
vim.api.nvim_create_user_command("Lazy", function(args)
M.cmd(vim.trim(args.args or ""))
vim.api.nvim_create_user_command("Lazy", function(cmd)
local args = vim.split(vim.trim(cmd.args or ""), " ")
local name = args[1]
table.remove(args, 1)
M.cmd(name, #args > 0 and args or nil)
end, {
nargs = "?",
desc = "Lazy",
complete = function(_, line)
---@type string?
local prefix = line:match("^%s*Lazy load (%w*)")
if prefix then
return M.complete_unloaded(prefix)
end
if line:match("^%s*Lazy %w+ ") then
return {}
end
local prefix = line:match("^%s*Lazy (%w*)") or ""
prefix = line:match("^%s*Lazy (%w*)") or ""
---@param key string
return vim.tbl_filter(function(key)

View File

@ -17,6 +17,11 @@ M.modes = {
{ name = "debug", key = "D", desc = "Show debug information", toggle = true },
{ name = "help", key = "?", desc = "Toggle this help page", toggle = true },
{ name = "clear", desc = "Clear finished tasks", hide = true },
{
name = "load",
desc = "Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`",
hide = true,
},
{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
{