Skip to content

Commit 9b36527

Browse files
committed
chore: class new is now generic
1 parent 5647bc3 commit 9b36527

File tree

18 files changed

+26
-24
lines changed

18 files changed

+26
-24
lines changed

lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434

3535
---@param node Node?
3636
function M.fn(node)
37-
node = node or core.get_explorer() --[[@as Node]]
37+
node = node or core.get_explorer()
3838
if not node then
3939
return
4040
end

lua/nvim-tree/class.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
---Generic class, useful for inheritence.
22
---@class (exact) Class
3-
---@field private __index? table
43
local Class = {}
54

6-
---@param o Class?
7-
---@return Class
5+
---@generic T
6+
---@param self T
7+
---@param o T|nil
8+
---@return T
89
function Class:new(o)
910
o = o or {}
1011

1112
setmetatable(o, self)
12-
self.__index = self
13+
self.__index = self ---@diagnostic disable-line: inject-field
1314

1415
return o
1516
end
1617

1718
---Object is an instance of class
1819
---This will start with the lowest class and loop over all the superclasses.
19-
---@param class table
20+
---@generic T
21+
---@param class T
2022
---@return boolean
2123
function Class:is(class)
2224
local mt = getmetatable(self)
@@ -32,7 +34,7 @@ end
3234
---Return object if it is an instance of class, otherwise nil
3335
---@generic T
3436
---@param class T
35-
---@return `T`|nil
37+
---@return T|nil
3638
function Class:as(class)
3739
return self:is(class) and self or nil
3840
end

lua/nvim-tree/explorer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function Explorer:create(path)
5959

6060
local o = RootNode:create(explorer_placeholder, path, "..", nil)
6161

62-
o = self:new(o) --[[@as Explorer]]
62+
o = self:new(o)
6363

6464
o.explorer = o
6565

lua/nvim-tree/git/runner.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function GitRunner:run(opts)
246246
opts = opts,
247247
statuses = {},
248248
}
249-
runner = GitRunner:new(runner) --[[@as GitRunner]]
249+
runner = GitRunner:new(runner)
250250

251251
return runner:execute()
252252
end

lua/nvim-tree/node/directory-link.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function DirectoryLinkNode:create(explorer, parent, absolute_path, link_to, name
2020
-- create DirectoryNode with the target path for the watcher
2121
local o = DirectoryNode:create(explorer, parent, link_to, name, fs_stat)
2222

23-
o = self:new(o) --[[@as DirectoryLinkNode]]
23+
o = self:new(o)
2424

2525
-- reset absolute path to the link itself
2626
o.absolute_path = absolute_path

lua/nvim-tree/node/directory.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function DirectoryNode:create(explorer, parent, absolute_path, name, fs_stat)
4343
open = false,
4444
hidden_stats = nil,
4545
}
46-
o = self:new(o) --[[@as DirectoryNode]]
46+
o = self:new(o)
4747

4848
o.watcher = require("nvim-tree.explorer.watch").create_watcher(o)
4949

lua/nvim-tree/node/file-link.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local FileLinkNode = FileNode:new()
1919
function FileLinkNode:create(explorer, parent, absolute_path, link_to, name, fs_stat, fs_stat_target)
2020
local o = FileNode:create(explorer, parent, absolute_path, name, fs_stat)
2121

22-
o = self:new(o) --[[@as FileLinkNode]]
22+
o = self:new(o)
2323

2424
o.type = "link"
2525
o.link_to = link_to

lua/nvim-tree/node/file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function FileNode:create(explorer, parent, absolute_path, name, fs_stat)
3131

3232
extension = string.match(name, ".?[^.]+%.(.*)") or "",
3333
}
34-
o = self:new(o) --[[@as FileNode]]
34+
o = self:new(o)
3535

3636
return o
3737
end

lua/nvim-tree/node/root.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local RootNode = DirectoryNode:new()
1212
function RootNode:create(explorer, absolute_path, name, fs_stat)
1313
local o = DirectoryNode:create(explorer, nil, absolute_path, name, fs_stat)
1414

15-
o = self:new(o) --[[@as RootNode]]
15+
o = self:new(o)
1616

1717
return o
1818
end

lua/nvim-tree/renderer/decorator/bookmarks.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function DecoratorBookmarks:create(opts, explorer)
1919
hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none,
2020
icon_placement = ICON_PLACEMENT[opts.renderer.icons.bookmarks_placement] or ICON_PLACEMENT.none,
2121
}
22-
o = self:new(o) --[[@as DecoratorBookmarks]]
22+
o = self:new(o)
2323

2424
if opts.renderer.icons.show.bookmarks then
2525
o.icon = {

0 commit comments

Comments
 (0)