mirror of
https://github.com/neovim/neovim.git
synced 2025-11-03 17:24:29 +00:00
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.
This commit is contained in:
@@ -300,6 +300,7 @@ Available events to hook into ~
|
||||
• *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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user