feat(pack): support user-defined data in plugin spec #35360

Problem:
The load function in opts was difficult to use if you wished to
customize based on the plugin being loaded.

You could get the name, but without some way to mark a spec, that was of
limited usefulness unless you wanted to hardcode a list of names in the
function, or write a wrapper around the whole thing

Solution:
Allow users to provide an arbitrary data field in plugin specs so that
they may receive info as to how to handle that plugin in load, get() and
events, and act upon it

Co-authored-by: BirdeeHub <birdee@localhost>
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
This commit is contained in:
Birdee
2025-08-21 10:08:29 -07:00
committed by GitHub
parent 9467731865
commit c522cb0e96
3 changed files with 50 additions and 2 deletions

View File

@@ -234,8 +234,10 @@ end
--- - Output of |vim.version.range()| to install the greatest/last semver tag
--- inside the version constraint.
--- @field version? string|vim.VersionRange
---
--- @field data? any Arbitrary data associated with a plugin.
--- @alias vim.pack.SpecResolved { src: string, name: string, version: nil|string|vim.VersionRange }
--- @alias vim.pack.SpecResolved { src: string, name: string, version: nil|string|vim.VersionRange, data: any|nil }
--- @param spec string|vim.pack.Spec
--- @return vim.pack.SpecResolved
@@ -247,7 +249,7 @@ local function normalize_spec(spec)
name = (type(name) == 'string' and name or ''):match('[^/]+$') or ''
vim.validate('spec.name', name, is_nonempty_string, true, 'non-empty string')
vim.validate('spec.version', spec.version, is_version, true, 'string or vim.VersionRange')
return { src = spec.src, name = name, version = spec.version }
return { src = spec.src, name = name, version = spec.version, data = spec.data }
end
--- @class (private) vim.pack.PlugInfo