Skip to content

Commit

Permalink
feat: added :Lazy load foobar.nvim to load a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 19, 2022
1 parent 8a0da3b commit 2dd6230
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 -->

Expand Down
4 changes: 1 addition & 3 deletions lua/lazy/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 30 additions & 3 deletions lua/lazy/view/commands.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
{
Expand Down

0 comments on commit 2dd6230

Please sign in to comment.