-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfunction.lua
46 lines (37 loc) · 1.21 KB
/
function.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local class = require('legendary.vendor.middleclass')
local util = require('legendary.util')
local Filters = require('legendary.data.filters')
---@class Function
---@field implementation function
---@field description string
---@field opts table
---@field filters (function[])|nil
---@field frecency_id fun(self):string
---@field class Function
local Function = class('Function')
Function:include(Filters) ---@diagnostic disable-line
function Function:parse(tbl) -- luacheck: no unused
vim.validate({
['1'] = { tbl[1], { 'function' } },
description = { util.get_desc(tbl), { 'string' } },
opts = { tbl.opts, { 'table' }, true },
})
local instance = Function()
instance.implementation = tbl[1]
instance.description = util.get_desc(tbl)
instance.opts = tbl.opts or {}
instance:parse_filters(tbl.filters)
return instance
end
function Function:apply() -- luacheck: no unused
-- no-op, just for the sake of keeping the same interface
-- between item types
return self
end
function Function:id()
return string.format('<function> %s %s', self.description, vim.inspect(self.opts or {}))
end
function Function:frecency_id()
return string.format('<function> %s', self.description)
end
return Function