mirror of
https://github.com/zoriya/lz.n.git
synced 2025-12-22 14:45:42 +00:00
chore: types: Lz -> lz.n prefix
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
local loader = require("lz.n.loader")
|
||||
|
||||
---@class LzCmdHandler: LzHandler
|
||||
---@class lz.n.CmdHandler: lz.n.Handler
|
||||
|
||||
---@type LzCmdHandler
|
||||
---@type lz.n.CmdHandler
|
||||
local M = {
|
||||
pending = {},
|
||||
type = "cmd",
|
||||
@@ -66,7 +66,7 @@ local function add_cmd(cmd)
|
||||
})
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.del(plugin)
|
||||
pcall(vim.api.nvim_del_user_command, plugin.cmd)
|
||||
for _, plugins in pairs(M.pending) do
|
||||
@@ -74,7 +74,7 @@ function M.del(plugin)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.add(plugin)
|
||||
if not plugin.cmd then
|
||||
return
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
local loader = require("lz.n.loader")
|
||||
|
||||
---@class LzEventOpts
|
||||
---@class lz.n.EventOpts
|
||||
---@field event string
|
||||
---@field group? string
|
||||
---@field exclude? string[] augroups to exclude
|
||||
---@field data? unknown
|
||||
---@field buffer? number
|
||||
|
||||
---@class LzEventHandler: LzHandler
|
||||
---@class lz.n.EventHandler: lz.n.Handler
|
||||
---@field events table<string,true>
|
||||
---@field group number
|
||||
---@field parse fun(spec: LzEventSpec): LzEvent
|
||||
---@field parse fun(spec: lz.n.EventSpec): lz.n.Event
|
||||
|
||||
---@type LzEventHandler
|
||||
---@type lz.n.EventHandler
|
||||
local M = {
|
||||
pending = {},
|
||||
events = {},
|
||||
@@ -27,7 +27,7 @@ local M = {
|
||||
elseif vim.islist(spec) then
|
||||
ret = { id = table.concat(spec, "|"), event = spec }
|
||||
else
|
||||
ret = spec --[[@as LzEvent]]
|
||||
ret = spec --[[@as lz.n.Event]]
|
||||
if not ret.id then
|
||||
---@diagnostic disable-next-line: assign-type-mismatch, param-type-mismatch
|
||||
ret.id = type(ret.event) == "string" and ret.event or table.concat(ret.event, "|")
|
||||
@@ -67,12 +67,12 @@ local event_triggers = {
|
||||
---@param event string
|
||||
---@param buf integer
|
||||
---@param data unknown
|
||||
---@return LzEventOpts[]
|
||||
---@return lz.n.EventOpts[]
|
||||
local function get_state(event, buf, data)
|
||||
---@type LzEventOpts[]
|
||||
---@type lz.n.EventOpts[]
|
||||
local state = {}
|
||||
while event do
|
||||
---@type LzEventOpts
|
||||
---@type lz.n.EventOpts
|
||||
local event_opts = {
|
||||
event = event,
|
||||
exclude = event ~= "FileType" and get_augroups(event) or nil,
|
||||
@@ -87,7 +87,7 @@ local function get_state(event, buf, data)
|
||||
end
|
||||
|
||||
-- Trigger an event
|
||||
---@param opts LzEventOpts
|
||||
---@param opts lz.n.EventOpts
|
||||
local function _trigger(opts)
|
||||
xpcall(
|
||||
function()
|
||||
@@ -106,7 +106,7 @@ end
|
||||
|
||||
-- Trigger an event. When a group is given, only the events in that group will be triggered.
|
||||
-- When exclude is set, the events in those groups will be skipped.
|
||||
---@param opts LzEventOpts
|
||||
---@param opts lz.n.EventOpts
|
||||
local function trigger(opts)
|
||||
if opts.group or opts.exclude == nil then
|
||||
return _trigger(opts)
|
||||
@@ -125,7 +125,7 @@ local function trigger(opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param event LzEvent
|
||||
---@param event lz.n.Event
|
||||
local function add_event(event)
|
||||
local done = false
|
||||
vim.api.nvim_create_autocmd(event.event, {
|
||||
@@ -149,7 +149,7 @@ local function add_event(event)
|
||||
})
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.add(plugin)
|
||||
for _, event in pairs(plugin.event or {}) do
|
||||
M.pending[event.id] = M.pending[event.id] or {}
|
||||
@@ -158,7 +158,7 @@ function M.add(plugin)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.del(plugin)
|
||||
for _, plugins in pairs(M.pending) do
|
||||
plugins[plugin.name] = nil
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
local event = require("lz.n.handler.event")
|
||||
|
||||
---@class LzFtHandler: LzHandler
|
||||
---@field parse fun(spec: LzEventSpec): LzEvent
|
||||
---@class lz.n.FtHandler: lz.n.Handler
|
||||
---@field parse fun(spec: lz.n.EventSpec): lz.n.Event
|
||||
|
||||
---@type LzFtHandler
|
||||
---@type lz.n.FtHandler
|
||||
local M = {
|
||||
pending = {},
|
||||
type = "ft",
|
||||
---@param value string
|
||||
---@return LzEvent
|
||||
---@return lz.n.Event
|
||||
parse = function(value)
|
||||
return {
|
||||
id = value,
|
||||
@@ -18,12 +18,12 @@ local M = {
|
||||
end,
|
||||
}
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.add(plugin)
|
||||
event.add(plugin)
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.del(plugin)
|
||||
event.del(plugin)
|
||||
end
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
---@class LzHandler
|
||||
---@field type LzHandlerTypes
|
||||
---@class lz.n.Handler
|
||||
---@field type lz.n.HandlerTypes
|
||||
---@field pending table<string, table<string, string>> -- key: plugin_name: plugin_name
|
||||
---@field add fun(plugin: LzPlugin)
|
||||
---@field del? fun(plugin: LzPlugin)
|
||||
---@field add fun(plugin: lz.n.Plugin)
|
||||
---@field del? fun(plugin: lz.n.Plugin)
|
||||
|
||||
local M = {}
|
||||
|
||||
---@enum LzHandlerTypes
|
||||
---@enum lz.n.HandlerTypes
|
||||
M.types = {
|
||||
cmd = "cmd",
|
||||
event = "event",
|
||||
@@ -21,24 +21,24 @@ local handlers = {
|
||||
keys = require("lz.n.handler.keys"),
|
||||
}
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
local function enable(plugin)
|
||||
for _, handler in pairs(handlers) do
|
||||
handler.add(plugin)
|
||||
end
|
||||
-- TODO: Change handler add implementations to take a LzPlugin
|
||||
-- TODO: Change handler add implementations to take a lz.n.Plugin
|
||||
end
|
||||
|
||||
function M.disable(plugin)
|
||||
for _, handler in pairs(handlers) do
|
||||
if type(handler.del) == "function" then
|
||||
-- TODO: Change handler del implementations to take a LzPlugin?
|
||||
-- TODO: Change handler del implementations to take a lz.n.Plugin?
|
||||
handler.del(plugin)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugins table<string, LzPlugin>
|
||||
---@param plugins table<string, lz.n.Plugin>
|
||||
function M.init(plugins)
|
||||
for _, plugin in pairs(plugins) do
|
||||
xpcall(
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
local loader = require("lz.n.loader")
|
||||
|
||||
---@class LzKeysHandler: LzHandler
|
||||
---@class lz.n.KeysHandler: lz.n.Handler
|
||||
|
||||
---@type LzKeysHandler
|
||||
---@type lz.n.KeysHandler
|
||||
local M = {
|
||||
pending = {},
|
||||
type = "keys",
|
||||
---@param value string|LzKeysSpec
|
||||
---@param value string|lz.n.KeysSpec
|
||||
---@param mode? string
|
||||
---@return LzKeys
|
||||
---@return lz.n.Keys
|
||||
parse = function(value, mode)
|
||||
value = type(value) == "string" and { value } or value --[[@as LzKeysSpec]]
|
||||
local ret = vim.deepcopy(value) --[[@as LzKeys]]
|
||||
value = type(value) == "string" and { value } or value --[[@as lz.n.KeysSpec]]
|
||||
local ret = vim.deepcopy(value) --[[@as lz.n.Keys]]
|
||||
ret.lhs = ret[1] or ""
|
||||
ret.rhs = ret[2]
|
||||
ret[1] = nil
|
||||
@@ -31,10 +31,10 @@ local M = {
|
||||
|
||||
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true }
|
||||
|
||||
---@param keys LzKeys
|
||||
---@return LzKeysBase
|
||||
---@param keys lz.n.Keys
|
||||
---@return lz.n.KeysBase
|
||||
local function get_opts(keys)
|
||||
---@type LzKeysBase
|
||||
---@type lz.n.KeysBase
|
||||
local opts = {}
|
||||
for k, v in pairs(keys) do
|
||||
if type(k) ~= "number" and not skip[k] then
|
||||
@@ -45,7 +45,7 @@ local function get_opts(keys)
|
||||
end
|
||||
|
||||
-- Create a mapping if it is managed by lz.n
|
||||
---@param keys LzKeys
|
||||
---@param keys lz.n.Keys
|
||||
---@param buf integer?
|
||||
local function set(keys, buf)
|
||||
if keys.rhs then
|
||||
@@ -58,7 +58,7 @@ end
|
||||
|
||||
-- Delete a mapping and create the real global
|
||||
-- mapping when needed
|
||||
---@param keys LzKeys
|
||||
---@param keys lz.n.Keys
|
||||
local function del(keys)
|
||||
pcall(vim.keymap.del, keys.mode, keys.lhs, {
|
||||
-- NOTE: for buffer-local mappings, we only delete the mapping for the current buffer
|
||||
@@ -72,7 +72,7 @@ local function del(keys)
|
||||
end
|
||||
end
|
||||
|
||||
---@param keys LzKeys
|
||||
---@param keys lz.n.Keys
|
||||
local function add_keys(keys)
|
||||
local lhs = keys.lhs
|
||||
local opts = get_opts(keys)
|
||||
@@ -124,7 +124,7 @@ local function add_keys(keys)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.add(plugin)
|
||||
for _, key in pairs(plugin.keys or {}) do
|
||||
M.pending[key.id] = M.pending[key.id] or {}
|
||||
@@ -133,7 +133,7 @@ function M.add(plugin)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M.del(plugin)
|
||||
for _, plugins in pairs(M.pending) do
|
||||
plugins[plugin.name] = nil
|
||||
|
||||
@@ -7,7 +7,7 @@ if not vim.loader or vim.fn.has("nvim-0.9.1") ~= 1 then
|
||||
error("lz.n requires Neovim >= 0.9.1")
|
||||
end
|
||||
|
||||
---@param spec string | LzSpec
|
||||
---@param spec string | lz.n.Spec
|
||||
function M.load(spec)
|
||||
if vim.g.lzn_did_load then
|
||||
return vim.notify("lz.n has already loaded your plugins.", vim.log.levels.WARN, { title = "lz.n" })
|
||||
@@ -17,7 +17,7 @@ function M.load(spec)
|
||||
if type(spec) == "string" then
|
||||
spec = { import = spec }
|
||||
end
|
||||
---@cast spec LzSpec
|
||||
---@cast spec lz.n.Spec
|
||||
local plugins = require("lz.n.spec").parse(spec)
|
||||
require("lz.n.loader").load_startup_plugins(plugins)
|
||||
require("lz.n.state").plugins = plugins
|
||||
|
||||
@@ -7,7 +7,7 @@ local M = {}
|
||||
local DEFAULT_PRIORITY = 50
|
||||
|
||||
---@package
|
||||
---@param plugin LzPlugin
|
||||
---@param plugin lz.n.Plugin
|
||||
function M._load(plugin)
|
||||
if plugin.enable == false or (type(plugin.enable) == "function" and not plugin.enable()) then
|
||||
return
|
||||
@@ -16,7 +16,7 @@ function M._load(plugin)
|
||||
-- TODO: Load plugin
|
||||
end
|
||||
|
||||
---@param plugins table<string, LzPlugin>
|
||||
---@param plugins table<string, lz.n.Plugin>
|
||||
local function run_before_all(plugins)
|
||||
for _, plugin in pairs(plugins) do
|
||||
if plugin.beforeAll then
|
||||
@@ -34,8 +34,8 @@ local function run_before_all(plugins)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugins table<string, LzPlugin>
|
||||
---@return LzPlugin[]
|
||||
---@param plugins table<string, lz.n.Plugin>
|
||||
---@return lz.n.Plugin[]
|
||||
local function get_eager_plugins(plugins)
|
||||
local result = {}
|
||||
for _, plugin in pairs(plugins) do
|
||||
@@ -44,15 +44,15 @@ local function get_eager_plugins(plugins)
|
||||
end
|
||||
end
|
||||
table.sort(result, function(a, b)
|
||||
---@cast a LzPlugin
|
||||
---@cast b LzPlugin
|
||||
---@cast a lz.n.Plugin
|
||||
---@cast b lz.n.Plugin
|
||||
return (a.priority or DEFAULT_PRIORITY) > (b.priority or DEFAULT_PRIORITY)
|
||||
end)
|
||||
return result
|
||||
end
|
||||
|
||||
--- Loads startup plugins, removing loaded plugins from the table
|
||||
---@param plugins table<string, LzPlugin>
|
||||
---@param plugins table<string, lz.n.Plugin>
|
||||
function M.load_startup_plugins(plugins)
|
||||
run_before_all(plugins)
|
||||
for _, plugin in pairs(get_eager_plugins(plugins)) do
|
||||
@@ -61,10 +61,10 @@ function M.load_startup_plugins(plugins)
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugins string | LzPlugin | string[] | LzPlugin[]
|
||||
---@param plugins string | lz.n.Plugin | string[] | lz.n.Plugin[]
|
||||
function M.load(plugins)
|
||||
plugins = (type(plugins) == "string" or plugins.name) and { plugins } or plugins
|
||||
---@cast plugins (string|LzPlugin)[]
|
||||
---@cast plugins (string|lz.n.Plugin)[]
|
||||
for _, plugin in pairs(plugins) do
|
||||
local loadable = true
|
||||
if type(plugin) == "string" then
|
||||
@@ -74,7 +74,7 @@ function M.load(plugins)
|
||||
vim.notify("Plugin " .. plugin .. " not found", vim.log.levels.ERROR, { title = "lz.n" })
|
||||
loadable = false
|
||||
end
|
||||
---@cast plugin LzPlugin
|
||||
---@cast plugin lz.n.Plugin
|
||||
end
|
||||
if loadable then
|
||||
M._load(plugin)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
---@param spec LzSpecImport
|
||||
---@param result table<string, LzPlugin>
|
||||
---@param spec lz.n.SpecImport
|
||||
---@param result table<string, lz.n.Plugin>
|
||||
local function import_spec(spec, result)
|
||||
if spec.import == "lz.n" then
|
||||
vim.schedule(function()
|
||||
@@ -45,10 +45,10 @@ local function import_spec(spec, result)
|
||||
M._normalize(mod, result)
|
||||
end
|
||||
|
||||
---@param spec LzPluginSpec
|
||||
---@return LzPlugin
|
||||
---@param spec lz.n.PluginSpec
|
||||
---@return lz.n.Plugin
|
||||
local function parse(spec)
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
---@diagnostic disable-next-line: assign-type-mismatch
|
||||
local result = vim.deepcopy(spec)
|
||||
local event_spec = spec.event
|
||||
@@ -57,25 +57,25 @@ local function parse(spec)
|
||||
end
|
||||
if type(event_spec) == "string" then
|
||||
local event = require("lz.n.handler.event").parse(event_spec)
|
||||
result.event[event.id] = event
|
||||
table.insert(result.event, event)
|
||||
elseif type(event_spec) == "table" then
|
||||
---@cast event_spec LzEventSpec[]
|
||||
---@cast event_spec lz.n.EventSpec[]
|
||||
for _, _event_spec in pairs(event_spec) do
|
||||
local event = require("lz.n.handler.event").parse(_event_spec)
|
||||
result.ft[event.id] = event
|
||||
table.insert(result.event, event)
|
||||
end
|
||||
end
|
||||
local ft_spec = spec.ft
|
||||
if ft_spec then
|
||||
result.ft = {}
|
||||
result.event = result.event or {}
|
||||
end
|
||||
if type(ft_spec) == "string" then
|
||||
local ft = require("lz.n.handler.ft").parse(ft_spec)
|
||||
result[ft.id] = ft
|
||||
table.insert(result.event, ft)
|
||||
elseif type(ft_spec) == "table" then
|
||||
for _, _ft_spec in pairs(ft_spec) do
|
||||
local ft = require("lz.n.handler.ft").parse(_ft_spec)
|
||||
result.ft[ft.id] = ft
|
||||
table.insert(result.event, ft)
|
||||
end
|
||||
end
|
||||
local keys_spec = spec.keys
|
||||
@@ -84,12 +84,12 @@ local function parse(spec)
|
||||
end
|
||||
if type(keys_spec) == "string" then
|
||||
local keys = require("lz.n.handler.keys").parse(keys_spec)
|
||||
result.keys[keys.id] = keys
|
||||
table.insert(result.keys, keys)
|
||||
elseif type(keys_spec) == "table" then
|
||||
---@cast keys_spec string[] | LzKeysSpec[]
|
||||
---@cast keys_spec string[] | lz.n.KeysSpec[]
|
||||
for _, _keys_spec in pairs(keys_spec) do
|
||||
local keys = require("lz.n.handler.keys").parse(_keys_spec)
|
||||
result.keys[keys.id] = keys
|
||||
table.insert(result.keys, keys)
|
||||
end
|
||||
end
|
||||
local cmd_spec = spec.cmd
|
||||
@@ -97,33 +97,33 @@ local function parse(spec)
|
||||
result.cmd = {}
|
||||
end
|
||||
if type(cmd_spec) == "string" then
|
||||
result.cmd[cmd_spec] = cmd_spec
|
||||
table.insert(result.cmd, cmd_spec)
|
||||
elseif type(cmd_spec) == "table" then
|
||||
for _, _cmd_spec in pairs(cmd_spec) do
|
||||
result.cmd[_cmd_spec] = _cmd_spec
|
||||
table.insert(result.cmd, _cmd_spec)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param spec LzSpec
|
||||
---@param result table<string, LzPlugin>
|
||||
---@param spec lz.n.Spec
|
||||
---@param result table<string, lz.n.Plugin>
|
||||
function M._normalize(spec, result)
|
||||
if #spec > 1 or vim.islist(spec) then
|
||||
for _, sp in ipairs(spec) do
|
||||
M._normalize(sp, result)
|
||||
end
|
||||
elseif spec.name then
|
||||
---@cast spec LzPluginSpec
|
||||
---@cast spec lz.n.PluginSpec
|
||||
result[spec.name] = parse(spec)
|
||||
elseif spec.import then
|
||||
---@cast spec LzSpecImport
|
||||
---@cast spec lz.n.SpecImport
|
||||
import_spec(spec, result)
|
||||
end
|
||||
end
|
||||
|
||||
---@param result table<string, LzPlugin>
|
||||
---@param result table<string, lz.n.Plugin>
|
||||
local function remove_disabled_plugins(result)
|
||||
for _, plugin in ipairs(result) do
|
||||
local disabled = plugin.enabled == false or (type(plugin.enabled) == "function" and not plugin.enabled())
|
||||
@@ -133,8 +133,8 @@ local function remove_disabled_plugins(result)
|
||||
end
|
||||
end
|
||||
|
||||
---@param spec LzSpec
|
||||
---@return table<string, LzPlugin>
|
||||
---@param spec lz.n.Spec
|
||||
---@return table<string, lz.n.Plugin>
|
||||
function M.parse(spec)
|
||||
local result = {}
|
||||
M._normalize(spec, result)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
---@type table<string, LzPlugin>
|
||||
---@type table<string, lz.n.Plugin>
|
||||
M.plugins = {}
|
||||
|
||||
return M
|
||||
|
||||
@@ -10,40 +10,40 @@ error("Cannot import a meta module")
|
||||
---@field name? string Name of the config function. Defaults to 'setup', the most common in the Neovim plugin community.
|
||||
---@field type 'func'
|
||||
|
||||
---@alias LzPluginOptsSpec VimGTable | ConfigFunction How a plugin accepts its options
|
||||
---@alias lz.n.PluginOptsSpec VimGTable | ConfigFunction How a plugin accepts its options
|
||||
|
||||
---@class LzPluginBase
|
||||
---@class lz.n.PluginBase
|
||||
---@field name string Display name and name used for plugin config files, e.g. "neorg"
|
||||
---@field optsSpec? LzPluginOptsSpec
|
||||
---@field optsSpec? lz.n.PluginOptsSpec
|
||||
---@field enabled? boolean|(fun():boolean)
|
||||
---@field enable? boolean|(fun():boolean) Whether to enable this plugin. Useful to disable plugins under certain conditions.
|
||||
---@field lazy? boolean
|
||||
---@field priority? number Only useful for lazy=false plugins to force loading certain plugins first. Default priority is 50
|
||||
|
||||
---@alias LzEvent {id:string, event:string[]|string, pattern?:string[]|string}
|
||||
---@alias LzEventSpec string|{event?:string|string[], pattern?:string|string[]}|string[]
|
||||
---@alias lz.n.Event {id:string, event:string[]|string, pattern?:string[]|string}
|
||||
---@alias lz.n.EventSpec string|{event?:string|string[], pattern?:string|string[]}|string[]
|
||||
|
||||
---@alias PluginOpts table|fun(self:LzPlugin, opts:table):table?
|
||||
---@alias PluginOpts table|fun(self:lz.n.Plugin, opts:table):table?
|
||||
|
||||
---@class LzPluginHooks
|
||||
---@field beforeAll? fun(self:LzPlugin) Will be run before loading any plugins
|
||||
---@field deactivate? fun(self:LzPlugin) Unload/Stop a plugin
|
||||
---@field after? fun(self:LzPlugin, opts:table)|true Will be executed when loading the plugin
|
||||
---@class lz.n.PluginHooks
|
||||
---@field beforeAll? fun(self:lz.n.Plugin) Will be run before loading any plugins
|
||||
---@field deactivate? fun(self:lz.n.Plugin) Unload/Stop a plugin
|
||||
---@field after? fun(self:lz.n.Plugin, opts:table)|true Will be executed when loading the plugin
|
||||
---@field opts? PluginOpts
|
||||
|
||||
---@class LzPluginHandlers
|
||||
---@field event? LzEvent[]
|
||||
---@field keys? LzKeys[]
|
||||
---@class lz.n.PluginHandlers
|
||||
---@field event? lz.n.Event[]
|
||||
---@field keys? lz.n.Keys[]
|
||||
---@field cmd? string[]
|
||||
|
||||
---@class LzPluginSpecHandlers
|
||||
---@field event? string|LzEventSpec[]
|
||||
---@class lz.n.PluginSpecHandlers
|
||||
---@field event? string|lz.n.EventSpec[]
|
||||
---@field cmd? string[]|string
|
||||
---@field ft? string[]|string
|
||||
---@field keys? string|string[]|LzKeysSpec[]
|
||||
---@field keys? string|string[]|lz.n.KeysSpec[]
|
||||
---@field module? false
|
||||
|
||||
---@class LzKeysBase: vim.keymap.set.Opts
|
||||
---@class lz.n.KeysBase: vim.keymap.set.Opts
|
||||
---@field desc? string
|
||||
---@field noremap? boolean
|
||||
---@field remap? boolean
|
||||
@@ -51,12 +51,12 @@ error("Cannot import a meta module")
|
||||
---@field nowait? boolean
|
||||
---@field ft? string|string[]
|
||||
|
||||
---@class LzKeysSpec: LzKeysBase
|
||||
---@class lz.n.KeysSpec: lz.n.KeysBase
|
||||
---@field [1] string lhs
|
||||
---@field [2]? string|fun()|false rhs
|
||||
---@field mode? string|string[]
|
||||
|
||||
---@class LzKeys: LzKeysBase
|
||||
---@class lz.n.Keys: lz.n.KeysBase
|
||||
---@field lhs string lhs
|
||||
---@field rhs? string|fun() rhs
|
||||
---@field mode? string
|
||||
@@ -64,13 +64,13 @@ error("Cannot import a meta module")
|
||||
---@field name string
|
||||
|
||||
---@package
|
||||
---@class LzPlugin: LzPluginBase,LzPluginHandlers,LzPluginHooks
|
||||
---@class lz.n.Plugin: lz.n.PluginBase,lz.n.PluginHandlers,lz.n.PluginHooks
|
||||
|
||||
---@class LzPluginSpec: LzPluginBase,LzPluginSpecHandlers,LzPluginHooks
|
||||
---@class lz.n.PluginSpec: lz.n.PluginBase,lz.n.PluginSpecHandlers,lz.n.PluginHooks
|
||||
|
||||
---@alias LzSpec LzPluginSpec|LzSpecImport|LzSpec[]
|
||||
---@alias lz.n.Spec lz.n.PluginSpec|lz.n.SpecImport|lz.n.Spec[]
|
||||
|
||||
---@class LzSpecImport
|
||||
---@class lz.n.SpecImport
|
||||
---@field import string spec module to import
|
||||
---@field enabled? boolean|(fun():boolean)
|
||||
---@field cond? boolean|(fun():boolean)
|
||||
|
||||
@@ -6,7 +6,7 @@ local spy = require("luassert.spy")
|
||||
|
||||
describe("handlers.cmd", function()
|
||||
it("Command only loads plugin once and executes plugin command", function()
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
cmd = { "Foo" },
|
||||
@@ -40,7 +40,7 @@ describe("handlers.cmd", function()
|
||||
vim.api.nvim_create_user_command("Foo", function() end, {})
|
||||
vim.api.nvim_create_user_command("Bar", function() end, {})
|
||||
end
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
cmd = commands,
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("handlers.event", function()
|
||||
)
|
||||
end)
|
||||
it("Event only loads plugin once", function()
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
event = { event.parse("BufEnter") },
|
||||
@@ -56,9 +56,9 @@ describe("handlers.event", function()
|
||||
assert.spy(spy_load).called(1)
|
||||
end)
|
||||
it("Multiple events only load plugin once", function()
|
||||
---@param events LzEvent[]
|
||||
---@param events lz.n.Event[]
|
||||
local function itt(events)
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
event = events,
|
||||
@@ -78,7 +78,7 @@ describe("handlers.event", function()
|
||||
itt({ event.parse("WinEnter"), event.parse("BufEnter") })
|
||||
end)
|
||||
it("Plugins' event handlers are triggered", function()
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
event = { event.parse("BufEnter") },
|
||||
|
||||
@@ -13,7 +13,7 @@ describe("handlers.ft", function()
|
||||
}, ft.parse("rust"))
|
||||
end)
|
||||
it("filetype event loads plugins", function()
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "Foo",
|
||||
event = { ft.parse("rust") },
|
||||
|
||||
@@ -21,7 +21,7 @@ describe("handlers.keys", function()
|
||||
end)
|
||||
it("Key only loads plugin once", function()
|
||||
local lhs = "<leader>tt"
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
keys = { keys.parse(lhs) },
|
||||
@@ -36,9 +36,9 @@ describe("handlers.keys", function()
|
||||
--
|
||||
end)
|
||||
it("Multiple keys only load plugin once", function()
|
||||
---@param lzkeys LzKeys[]
|
||||
---@param lzkeys lz.n.Keys[]
|
||||
local function itt(lzkeys)
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "foo",
|
||||
keys = lzkeys,
|
||||
@@ -57,7 +57,7 @@ describe("handlers.keys", function()
|
||||
end)
|
||||
it("Plugins' keymaps are triggered", function()
|
||||
local lhs = "<leader>xy"
|
||||
---@type LzPlugin
|
||||
---@type lz.n.Plugin
|
||||
local plugin = {
|
||||
name = "baz",
|
||||
keys = { keys.parse(lhs) },
|
||||
|
||||
Reference in New Issue
Block a user