Skip to content

Commit 4216828

Browse files
committed
feat: add type annotations for plenary.class
1 parent 260f558 commit 4216828

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

lua/plenary/class.lua

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
---Copyright (c) 2014, rxi
55
---@brief ]]
66

7-
---@class Object
7+
---@class PlenaryClass
8+
---@overload fun(...): PlenaryClass
89
local Object = {}
910
Object.__index = Object
1011

1112
---Does nothing.
1213
---You have to implement this yourself for extra functionality when initializing
13-
---@param self Object
14+
---@type fun(self: PlenaryClass, ...)
1415
function Object:new() end
1516

1617
---Create a new class/object by extending the base Object class.
1718
---The extended object will have a field called `super` that will access the super class.
18-
---@param self Object
19-
---@return Object
19+
---@return PlenaryClass
2020
function Object:extend()
2121
local cls = {}
2222
for k, v in pairs(self) do
@@ -31,8 +31,7 @@ function Object:extend()
3131
end
3232

3333
---Implement a mixin onto this Object.
34-
---@param self Object
35-
---@param nil ...
34+
---@param ... any
3635
function Object:implement(...)
3736
for _, cls in pairs { ... } do
3837
for k, v in pairs(cls) do
@@ -45,8 +44,7 @@ end
4544

4645
---Checks if the object is an instance
4746
---This will start with the lowest class and loop over all the superclasses.
48-
---@param self Object
49-
---@param T Object
47+
---@param T PlenaryClass
5048
---@return boolean
5149
function Object:is(T)
5250
local mt = getmetatable(self)
@@ -61,16 +59,14 @@ end
6159

6260
---The default tostring implementation for an object.
6361
---You can override this to provide a different tostring.
64-
---@param self Object
6562
---@return string
6663
function Object:__tostring()
6764
return "Object"
6865
end
6966

7067
---You can call the class the initialize it without using `Object:new`.
71-
---@param self Object
72-
---@param nil ...
73-
---@return Object
68+
---@param ... any
69+
---@return PlenaryClass
7470
function Object:__call(...)
7571
local obj = setmetatable({}, self)
7672
obj:new(...)

lua/plenary/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Lazy load everything into plenary.
22
---@class Plenary
33
---@field async PlenaryAsync
4+
---@field class PlenaryClass
45
---@field context_manager PlenaryContextManager
56
---@field curl PlenaryCurl
67
---@field functional PlenaryFunctional

0 commit comments

Comments
 (0)