aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/pack.lua
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-07-29 20:15:58 +0300
committerEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-08-02 15:00:41 +0300
commit267bbe64cb4fc1e5d3055307d11872f948a4e44f (patch)
tree2b1d8db5b5e404336e0869c06d3e12da52a8cd45 /runtime/lua/vim/pack.lua
parenta203961535057ca335b8a02b65c032a287bba37a (diff)
downloadrneovim-267bbe64cb4fc1e5d3055307d11872f948a4e44f.tar.gz
rneovim-267bbe64cb4fc1e5d3055307d11872f948a4e44f.tar.bz2
rneovim-267bbe64cb4fc1e5d3055307d11872f948a4e44f.zip
fix(pack): validate installed plugins in `update()` and `del()`
Problem: Currently `update()` and `del()` silently ignore input plugin names that are not for already installed plugin. This might lead to confusion because they are not explicitly reported. Solution: Check that all input names are for installed plugins and error otherwise.
Diffstat (limited to 'runtime/lua/vim/pack.lua')
-rw-r--r--runtime/lua/vim/pack.lua29
1 files changed, 15 insertions, 14 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
index 7d83921763..3693fbe5b1 100644
--- a/runtime/lua/vim/pack.lua
+++ b/runtime/lua/vim/pack.lua
@@ -324,6 +324,7 @@ end
local function plug_list_from_names(names)
local all_plugins = M.get()
local plugs = {} --- @type vim.pack.Plug[]
+ local used_names = {} --- @type table<string,boolean>
-- Preserve plugin order; might be important during checkout or event trigger
for _, p_data in ipairs(all_plugins) do
-- NOTE: By default include only active plugins (and not all on disk). Using
@@ -333,9 +334,18 @@ local function plug_list_from_names(names)
--- @cast names string[]
if (not names and p_data.active) or vim.tbl_contains(names or {}, p_data.spec.name) then
plugs[#plugs + 1] = new_plug(p_data.spec)
+ used_names[p_data.spec.name] = true
end
end
+ if vim.islist(names) and #plugs ~= #names then
+ --- @param n string
+ local unused = vim.tbl_filter(function(n)
+ return not used_names[n]
+ end, names)
+ error('The following plugins are not installed: ' .. table.concat(unused, ', '))
+ end
+
return plugs
end
@@ -878,11 +888,6 @@ function M.update(names, opts)
--- @async
--- @param p vim.pack.Plug
local function do_update(p)
- if not p.info.installed then
- notify(('Cannot update %s - not found'):format(p.spec.name), 'WARN')
- return
- end
-
-- Fetch
-- Using '--tags --force' means conflicting tags will be synced with remote
git_cmd(
@@ -945,17 +950,13 @@ function M.del(names)
end
for _, p in ipairs(plug_list) do
- if not p.info.installed then
- notify(("Plugin '%s' is not installed"):format(p.spec.name), 'WARN')
- else
- trigger_event(p, 'PackChangedPre', 'delete')
+ trigger_event(p, 'PackChangedPre', 'delete')
- vim.fs.rm(p.path, { recursive = true, force = true })
- active_plugins[p.path] = nil
- notify(("Removed plugin '%s'"):format(p.spec.name), 'INFO')
+ vim.fs.rm(p.path, { recursive = true, force = true })
+ active_plugins[p.path] = nil
+ notify(("Removed plugin '%s'"):format(p.spec.name), 'INFO')
- trigger_event(p, 'PackChanged', 'delete')
- end
+ trigger_event(p, 'PackChanged', 'delete')
end
end