diff options
Diffstat (limited to 'runtime/lua/vim/pack.lua')
| -rw-r--r-- | runtime/lua/vim/pack.lua | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index 1a0a3c4540..f17fce56a9 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -97,6 +97,7 @@ --- - [PackChanged]() - after plugin's state has changed. --- --- Each event populates the following |event-data| fields: +--- - `active` - whether plugin was added via |vim.pack.add()| to current session. --- - `kind` - one of "install" (install on disk), "update" (update existing --- plugin), "delete" (delete from disk). --- - `spec` - plugin's specification with defaults made explicit. @@ -408,11 +409,18 @@ local function plug_list_from_names(names) return plugs end +--- Map from plugin path to its data. +--- Use map and not array to avoid linear lookup during startup. +--- @type table<string, { plug: vim.pack.Plug, id: integer }?> +local active_plugins = {} +local n_active_plugins = 0 + --- @param p vim.pack.Plug --- @param event_name 'PackChangedPre'|'PackChanged' --- @param kind 'install'|'update'|'delete' local function trigger_event(p, event_name, kind) - local data = { kind = kind, spec = vim.deepcopy(p.spec), path = p.path } + local active = active_plugins[p.path] ~= nil + local data = { active = active, kind = kind, spec = vim.deepcopy(p.spec), path = p.path } api.nvim_exec_autocmds(event_name, { pattern = p.path, data = data }) end @@ -686,12 +694,6 @@ local function infer_update_details(p) p.info.update_details = table.concat(newer_semver_tags, '\n') end ---- Map from plugin path to its data. ---- Use map and not array to avoid linear lookup during startup. ---- @type table<string, { plug: vim.pack.Plug, id: integer }?> -local active_plugins = {} -local n_active_plugins = 0 - --- @param plug vim.pack.Plug --- @param load boolean|fun(plug_data: {spec: vim.pack.Spec, path: string}) local function pack_add(plug, load) |