feat(pack): rebuild plugins on :PluginUpdate
This commit is contained in:
+34
-5
@@ -17,14 +17,43 @@ vim.api.nvim_create_user_command("PluginUnwatch", function()
|
|||||||
require("pack").unwatch()
|
require("pack").unwatch()
|
||||||
end, { desc = "Stop watching plugin configs" })
|
end, { desc = "Stop watching plugin configs" })
|
||||||
|
|
||||||
|
local function complete_plugin_names(lead)
|
||||||
|
return vim.tbl_filter(function(name)
|
||||||
|
return name:find(lead, 1, true) == 1
|
||||||
|
end, require("pack").get_names())
|
||||||
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("PluginReload", function(opts)
|
vim.api.nvim_create_user_command("PluginReload", function(opts)
|
||||||
require("pack").reload_plugin(opts.args)
|
require("pack").reload_plugin(opts.args)
|
||||||
end, {
|
end, {
|
||||||
nargs = 1,
|
nargs = 1,
|
||||||
complete = function(lead)
|
complete = complete_plugin_names,
|
||||||
return vim.tbl_filter(function(name)
|
|
||||||
return name:find(lead, 1, true) == 1
|
|
||||||
end, require("pack").get_names())
|
|
||||||
end,
|
|
||||||
desc = "Reload a plugin config by name",
|
desc = "Reload a plugin config by name",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("PluginUpdate", function(opts)
|
||||||
|
local names = #opts.fargs > 0 and opts.fargs or nil
|
||||||
|
require("pack").update(names)
|
||||||
|
end, {
|
||||||
|
nargs = "*",
|
||||||
|
complete = complete_plugin_names,
|
||||||
|
desc = "Update plugins (fetch from remote)",
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("PluginUpdateOffline", function(opts)
|
||||||
|
local names = #opts.fargs > 0 and opts.fargs or nil
|
||||||
|
require("pack").update(names, { offline = true })
|
||||||
|
end, {
|
||||||
|
nargs = "*",
|
||||||
|
complete = complete_plugin_names,
|
||||||
|
desc = "Show pending plugin updates without fetching from remote",
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("PluginRestore", function(opts)
|
||||||
|
local names = #opts.fargs > 0 and opts.fargs or nil
|
||||||
|
require("pack").update(names, { target = "lockfile" })
|
||||||
|
end, {
|
||||||
|
nargs = "*",
|
||||||
|
complete = complete_plugin_names,
|
||||||
|
desc = "Restore plugins to revisions in the lockfile",
|
||||||
|
})
|
||||||
|
|||||||
@@ -233,14 +233,6 @@ vim.keymap.set("n", "<leader>fD", vim.diagnostic.setqflist)
|
|||||||
vim.keymap.set("n", "grt", vim.lsp.buf.type_definition)
|
vim.keymap.set("n", "grt", vim.lsp.buf.type_definition)
|
||||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition)
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition)
|
||||||
|
|
||||||
vim.keymap.set("n", "<leader>pp", function()
|
|
||||||
vim.pack.update(nil, { offline = true })
|
|
||||||
end)
|
|
||||||
vim.keymap.set("n", "<leader>pu", vim.pack.update)
|
|
||||||
vim.keymap.set("n", "<leader>pr", function()
|
|
||||||
vim.pack.update(nil, { target = "lockfile" })
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Default bindings that are good to know:
|
-- Default bindings that are good to know:
|
||||||
-- insert mode:
|
-- insert mode:
|
||||||
-- <C-T> - indent, see :h i_CTRL-T
|
-- <C-T> - indent, see :h i_CTRL-T
|
||||||
|
|||||||
+48
-1
@@ -130,12 +130,45 @@ local watcher = nil
|
|||||||
---@type ow.Util.KeyedDebounceHandle<string>?
|
---@type ow.Util.KeyedDebounceHandle<string>?
|
||||||
local on_change_handle = nil
|
local on_change_handle = nil
|
||||||
|
|
||||||
|
---@alias ow.Pack.Hook fun(ev: ow.Pack.Event.Data)
|
||||||
|
|
||||||
|
---@type table<string, ow.Pack.Hook>
|
||||||
|
local hooks = {}
|
||||||
|
|
||||||
---@class ow.Pack
|
---@class ow.Pack
|
||||||
---@field plugins ow.Pack.Plugin[]
|
---@field plugins ow.Pack.Plugin[]
|
||||||
local M = {
|
local M = {
|
||||||
plugins = {},
|
plugins = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param fn ow.Pack.Hook
|
||||||
|
function M.register_hook(name, fn)
|
||||||
|
hooks[name] = fn
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup_event_listener()
|
||||||
|
local group =
|
||||||
|
vim.api.nvim_create_augroup("ow.Pack.events", { clear = true })
|
||||||
|
vim.api.nvim_create_autocmd("PackChanged", {
|
||||||
|
group = group,
|
||||||
|
---@param ev ow.Pack.Event
|
||||||
|
callback = function(ev)
|
||||||
|
local name = ev.data.spec.name
|
||||||
|
if not name then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if ev.data.kind ~= "install" and ev.data.kind ~= "update" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local hook = hooks[name]
|
||||||
|
if hook then
|
||||||
|
hook(ev.data)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
---@return string[]
|
---@return string[]
|
||||||
function M.get_names()
|
function M.get_names()
|
||||||
return vim.tbl_map(function(p)
|
return vim.tbl_map(function(p)
|
||||||
@@ -277,11 +310,25 @@ function M.setup(specs)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
for _, plugin in ipairs(M.plugins) do
|
for _, plugin in ipairs(M.plugins) do
|
||||||
if plugin.build and changed[plugin.name] then
|
if plugin.build then
|
||||||
|
if changed[plugin.name] then
|
||||||
run_build(plugin)
|
run_build(plugin)
|
||||||
end
|
end
|
||||||
|
M.register_hook(plugin.name, function(ev)
|
||||||
|
plugin.path = ev.path
|
||||||
|
run_build(plugin)
|
||||||
|
end)
|
||||||
|
end
|
||||||
load(plugin.name, false)
|
load(plugin.name, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setup_event_listener()
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param names? string[]
|
||||||
|
---@param opts? table
|
||||||
|
function M.update(names, opts)
|
||||||
|
vim.pack.update(names, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user