diff options
| author | Evgeni Chasnovski <evgeni.chasnovski@gmail.com> | 2025-10-23 17:50:03 +0300 |
|---|---|---|
| committer | Evgeni Chasnovski <evgeni.chasnovski@gmail.com> | 2025-10-23 17:50:03 +0300 |
| commit | a9db6ec6fa127b57912bc59e5d03f7e99d22607f (patch) | |
| tree | 9b4f89856ff5aae6dd1fc635ef03e0ff50695166 /runtime/lua/vim/pack.lua | |
| parent | c732133efead31f2ff23d5f4ceac639505add6e8 (diff) | |
| download | rneovim-a9db6ec6fa127b57912bc59e5d03f7e99d22607f.tar.gz rneovim-a9db6ec6fa127b57912bc59e5d03f7e99d22607f.tar.bz2 rneovim-a9db6ec6fa127b57912bc59e5d03f7e99d22607f.zip | |
feat(pack): add `active` field to `PackChanged` event data
Problem: Inside `PackChanged[Pre]` callbacks it might be useful to tell
if the affected plugin is active or not. It is already possible via
extra `vim.pack.get({ 'plug-name' })[1].active`, but it is not quite
user-friendly for something that might be needed frequently in real
world use cases.
Solution: Supply extra `active` event data field.
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) |