mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user