diff --git a/README.md b/README.md index d74a095c..c14f9989 100644 --- a/README.md +++ b/README.md @@ -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 -| Command | Lua | Key Mapping | Description | -| --------------------------------- | --------------------------- | ----------- | ------------------------------------------------------ | -| `:Lazy home` or `:LazyHome` | `require("lazy").home()` | `` | Go back to plugin list | -| `:Lazy install` or `:LazyInstall` | `require("lazy").install()` | `` | Install missing plugins | -| `:Lazy update` or `:LazyUpdate` | `require("lazy").update()` | `` | Update all plugins. This will also update the lockfile | -| `:Lazy sync` or `:LazySync` | `require("lazy").sync()` | `` | Run install, clean and update | -| `:Lazy clean` or `:LazyClean` | `require("lazy").clean()` | `` | Clean plugins that are no longer needed | -| `:Lazy check` or `:LazyCheck` | `require("lazy").check()` | `` | Check for updates and show the log (git fetch) | -| `:Lazy log` or `:LazyLog` | `require("lazy").log()` | `` | Show recent updates for all plugins | -| `:Lazy restore` or `:LazyRestore` | `require("lazy").restore()` | `` | Updates all plugins to the state in the lockfile | -| `:Lazy profile` or `:LazyProfile` | `require("lazy").profile()` | `

` | Show detailed profiling | -| `:Lazy debug` or `:LazyDebug` | `require("lazy").debug()` | `` | 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()` | `` | Go back to plugin list | +| `:Lazy install` | `require("lazy").install()` | `` | Install missing plugins | +| `:Lazy update` | `require("lazy").update()` | `` | Update all plugins. This will also update the lockfile | +| `:Lazy sync` | `require("lazy").sync()` | `` | Run install, clean and update | +| `:Lazy clean` | `require("lazy").clean()` | `` | Clean plugins that are no longer needed | +| `:Lazy check` | `require("lazy").check()` | `` | Check for updates and show the log (git fetch) | +| `:Lazy log` | `require("lazy").log()` | `` | Show recent updates for all plugins | +| `:Lazy restore` | `require("lazy").restore()` | `` | Updates all plugins to the state in the lockfile | +| `:Lazy profile` | `require("lazy").profile()` | `

` | Show detailed profiling | +| `:Lazy debug` | `require("lazy").debug()` | `` | 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` | diff --git a/lua/lazy/docs.lua b/lua/lazy/docs.lua index 7be8f55f..965f4e33 100644 --- a/lua/lazy/docs.lua +++ b/lua/lazy/docs.lua @@ -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, diff --git a/lua/lazy/view/commands.lua b/lua/lazy/view/commands.lua index 8abfe407..7427e455 100644 --- a/lua/lazy/view/commands.lua +++ b/lua/lazy/view/commands.lua @@ -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) diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua index 04dd42dc..b4406202 100644 --- a/lua/lazy/view/init.lua +++ b/lua/lazy/view/init.lua @@ -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" }, {