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 = { performance = {
cache = { cache = {
enabled = true, 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. -- Once one of the following events triggers, caching will be disabled.
-- To cache all modules, set this to `{}`, but that is not recommended. -- To cache all modules, set this to `{}`, but that is not recommended.
-- The default is to disable on: -- The default is to disable on:
@ -336,19 +336,20 @@ Alternatively you can start any operation with a specific command, sub command o
<!-- commands:start --> <!-- commands:start -->
| Command | Lua | Key Mapping | Description | | Command | Lua | Key Mapping | Description |
| --------------------------------- | --------------------------- | ----------- | ------------------------------------------------------ | | --------------- | --------------------------- | ----------- | --------------------------------------------------------------------------------------------- |
| `:Lazy home` or `:LazyHome` | `require("lazy").home()` | `<H>` | Go back to plugin list | | `:Lazy home` | `require("lazy").home()` | `<H>` | Go back to plugin list |
| `:Lazy install` or `:LazyInstall` | `require("lazy").install()` | `<I>` | Install missing plugins | | `:Lazy install` | `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 update` | `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 sync` | `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 clean` | `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 check` | `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 log` | `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 restore` | `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 profile` | `require("lazy").profile()` | `<P>` | Show detailed profiling |
| `:Lazy debug` or `:LazyDebug` | `require("lazy").debug()` | `<D>` | Show debug information | | `:Lazy debug` | `require("lazy").debug()` | `<D>` | Show debug information |
| `:Lazy help` or `:LazyHelp` | `require("lazy").help()` | `<?>` | Toggle this help page | | `:Lazy help` | `require("lazy").help()` | `<?>` | Toggle this help page |
| `:Lazy clear` or `:LazyClear` | `require("lazy").clear()` | | Clear finished tasks | | `: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 --> <!-- commands:end -->

View File

@ -83,9 +83,7 @@ function M.commands()
for _, mode in ipairs(modes) do for _, mode in ipairs(modes) do
if not mode.plugin and commands[mode.name] then if not mode.plugin and commands[mode.name] then
lines[#lines + 1] = { lines[#lines + 1] = {
("`:Lazy %s`"):format(mode.name) .. " or " .. ("`:Lazy%s`"):format( ("`:Lazy %s`"):format(mode.name),
mode.name:sub(1, 1):upper() .. mode.name:sub(2)
),
([[`require("lazy").%s()`]]):format(mode.name), ([[`require("lazy").%s()`]]):format(mode.name),
mode.key and ("`<%s>`"):format(mode.key) or "", mode.key and ("`<%s>`"):format(mode.key) or "",
mode.desc, mode.desc,

View File

@ -1,6 +1,7 @@
local View = require("lazy.view") local View = require("lazy.view")
local Manage = require("lazy.manage") local Manage = require("lazy.manage")
local Util = require("lazy.util") local Util = require("lazy.util")
local Config = require("lazy.core.config")
local M = {} local M = {}
@ -60,20 +61,46 @@ M.commands = {
restore = function(plugins) restore = function(plugins)
Manage.update({ clear = true, lockfile = true, mode = "restore", plugins = plugins }) Manage.update({ clear = true, lockfile = true, mode = "restore", plugins = plugins })
end, 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() function M.setup()
vim.api.nvim_create_user_command("Lazy", function(args) vim.api.nvim_create_user_command("Lazy", function(cmd)
M.cmd(vim.trim(args.args or "")) 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, { end, {
nargs = "?", nargs = "?",
desc = "Lazy", desc = "Lazy",
complete = function(_, line) 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 if line:match("^%s*Lazy %w+ ") then
return {} return {}
end end
local prefix = line:match("^%s*Lazy (%w*)") or "" prefix = line:match("^%s*Lazy (%w*)") or ""
---@param key string ---@param key string
return vim.tbl_filter(function(key) 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 = "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 }, { 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" }, { plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
{ {