11local git = require (" nvim-tree.git" )
22
3+ local Class = require (" nvim-tree.class" )
4+
35--- TODO #2886
46--- TODO remove all @cast
57--- TODO remove all references to directory fields:
68
79--- Abstract Node class.
810--- Uses the abstract factory pattern to instantiate child instances.
9- --- @class (exact ) BaseNode
10- --- @field private __index ? table
11+ --- @class (exact ) BaseNode : Class
1112--- @field type NODE_TYPE
1213--- @field explorer Explorer
1314--- @field absolute_path string
@@ -20,51 +21,17 @@ local git = require("nvim-tree.git")
2021--- @field watcher Watcher ?
2122--- @field diag_status DiagStatus ?
2223--- @field is_dot boolean cached is_dotfile
23- local BaseNode = {}
24+ local BaseNode = Class : new ()
2425
2526--- @alias Node RootNode | BaseNode | DirectoryNode | FileNode | DirectoryLinkNode | FileLinkNode
2627
27- --- @param o BaseNode ?
28- --- @return BaseNode
29- function BaseNode :new (o )
30- o = o or {}
31-
32- setmetatable (o , self )
33- self .__index = self
34-
35- return o
36- end
37-
3828function BaseNode :destroy ()
3929 if self .watcher then
4030 self .watcher :destroy ()
4131 self .watcher = nil
4232 end
4333end
4434
45- --- Object is an instance of class
46- --- This will start with the lowest class and loop over all the superclasses.
47- --- @param class table
48- --- @return boolean
49- function BaseNode :is (class )
50- local mt = getmetatable (self )
51- while mt do
52- if mt == class then
53- return true
54- end
55- mt = getmetatable (mt )
56- end
57- return false
58- end
59-
60- --- Return object if it is an instance of class, otherwise nil
61- --- @generic T
62- --- @param class T
63- --- @return ` T ` |nil
64- function BaseNode :as (class )
65- return self :is (class ) and self or nil
66- end
67-
6835--- @return boolean
6936function BaseNode :has_one_child_folder ()
7037 return # self .nodes == 1 and self .nodes [1 ].nodes and vim .loop .fs_access (self .nodes [1 ].absolute_path , " R" ) or false
0 commit comments