1- -- This file should have no requires. Everything must be lazy loaded.
2- -- The user must be able to require api cheaply and run setup cheaply.
1+ local view = require (" nvim-tree.view" )
2+ local actions = require (" nvim-tree.actions" )
3+
4+ local DirectoryNode = require (" nvim-tree.node.directory" )
5+ local FileLinkNode = require (" nvim-tree.node.file-link" )
6+ local RootNode = require (" nvim-tree.node.root" )
37
48--- Invoke a method on the singleton explorer.
9+ --- Print error when setup not called.
510--- @param explorer_method string explorer method name
611--- @return fun ( ... ): any
712local function wrap_explorer (explorer_method )
@@ -36,6 +41,7 @@ local function wrap_node_or_nil(fn)
3641end
3742
3843--- Invoke a member's method on the singleton explorer.
44+ --- Print error when setup not called.
3945--- @param explorer_member string explorer member name
4046--- @param member_method string method name to invoke on member
4147--- @param ... any passed to method
@@ -51,6 +57,7 @@ local function wrap_explorer_member_args(explorer_member, member_method, ...)
5157end
5258
5359--- Invoke a member's method on the singleton explorer.
60+ --- Print error when setup not called.
5461--- @param explorer_member string explorer member name
5562--- @param member_method string method name to invoke on member
5663--- @return fun ( ... ): any
7178--- @param node Node
7279--- @param edit_opts NodeEditOpts ?
7380local function edit (mode , node , edit_opts )
74- local actions = require (" nvim-tree.actions" )
75- local view = require (" nvim-tree.view" )
76-
77- local file_link = node :as (require (" nvim-tree.node.file-link" ))
81+ local file_link = node :as (FileLinkNode )
7882 local path = file_link and file_link .link_to or node .absolute_path
7983 local cur_tabpage = vim .api .nvim_get_current_tabpage ()
8084
@@ -105,11 +109,11 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
105109 --- @param node Node
106110 --- @param edit_opts NodeEditOpts ?
107111 return function (node , edit_opts )
108- local root = node :as (require ( " nvim-tree.node.root " ) )
109- local dir = node :as (require ( " nvim-tree.node.directory " ) )
112+ local root = node :as (RootNode )
113+ local dir = node :as (DirectoryNode )
110114
111115 if root or node .name == " .." then
112- require ( " nvim-tree. actions" ) .root .change_dir .fn (" .." )
116+ actions .root .change_dir .fn (" .." )
113117 elseif dir then
114118 dir :expand_or_collapse (toggle_group )
115119 elseif not toggle_group then
@@ -121,45 +125,45 @@ end
121125--- Hydrate all implementations barring those that were called during hydrate_pre
122126--- @param api table
123127local function hydrate_post (api )
124- api .tree .open = function (...) require ( " nvim-tree. actions" ) .tree .open .fn ( ... ) end
128+ api .tree .open = actions .tree .open .fn
125129 api .tree .focus = api .tree .open
126130
127- api .tree .toggle = function (...) require ( " nvim-tree. actions" ) .tree .toggle .fn ( ... ) end
128- api .tree .close = function (...) require ( " nvim-tree. view" ) .close ( ... ) end
129- api .tree .close_in_this_tab = function () require ( " nvim-tree. view" ) .close_this_tab_only () end
130- api .tree .close_in_all_tabs = function () require ( " nvim-tree. view" ) .close_all_tabs () end
131+ api .tree .toggle = actions .tree .toggle .fn
132+ api .tree .close = view .close
133+ api .tree .close_in_this_tab = view .close_this_tab_only
134+ api .tree .close_in_all_tabs = view .close_all_tabs
131135 api .tree .reload = wrap_explorer (" reload_explorer" )
132136
133- api .tree .resize = function (...) require ( " nvim-tree. actions" ) .tree .resize .fn ( ... ) end
137+ api .tree .resize = actions .tree .resize .fn
134138
135- api .tree .change_root = function (...) require (" nvim-tree" ).change_dir ( ... ) end
139+ api .tree .change_root = require (" nvim-tree" ).change_dir
136140
137141 api .tree .change_root_to_node = wrap_node (wrap_explorer (" change_dir_to_node" ))
138142 api .tree .change_root_to_parent = wrap_node (wrap_explorer (" dir_up" ))
139143 api .tree .get_node_under_cursor = wrap_explorer (" get_node_at_cursor" )
140144 api .tree .get_nodes = wrap_explorer (" get_nodes" )
141145
142- api .tree .find_file = function (...) require ( " nvim-tree. actions" ) .tree .find_file .fn ( ... ) end
143- api .tree .search_node = function () require ( " nvim-tree. actions" ) .finders .search_node .fn () end
146+ api .tree .find_file = actions .tree .find_file .fn
147+ api .tree .search_node = actions .finders .search_node .fn
144148
145- api .tree .collapse_all = function (...) require ( " nvim-tree. actions" ) .tree .modifiers .collapse .all ( ... ) end
149+ api .tree .collapse_all = actions .tree .modifiers .collapse .all
146150
147- api .tree .expand_all = wrap_node (require ( " nvim-tree. actions" ) .tree .modifiers .expand .all )
151+ api .tree .expand_all = wrap_node (actions .tree .modifiers .expand .all )
148152 api .tree .toggle_help = function () require (" nvim-tree.help" ).toggle () end
149- api .tree .is_tree_buf = function (... ) require (" nvim-tree.utils" ).is_nvim_tree_buf (... ) end
153+ api .tree .is_tree_buf = function () require (" nvim-tree.utils" ).is_nvim_tree_buf () end
150154
151- api .tree .is_visible = function (...) require ( " nvim-tree. view" ) .is_visible ( ... ) end
155+ api .tree .is_visible = view .is_visible
152156
153- api .tree .winid = function (...) require ( " nvim-tree. view" ) .winid ( ... ) end
157+ api .tree .winid = view .winid
154158
155- api .fs .create = wrap_node_or_nil (require ( " nvim-tree. actions" ) .fs .create_file .fn )
156- api .fs .remove = wrap_node (require ( " nvim-tree. actions" ) .fs .remove_file .fn )
157- api .fs .trash = wrap_node (require ( " nvim-tree. actions" ) .fs .trash .fn )
158- api .fs .rename_node = wrap_node (require ( " nvim-tree. actions" ) .fs .rename_file .fn (" :t" ))
159- api .fs .rename = wrap_node (require ( " nvim-tree. actions" ) .fs .rename_file .fn (" :t" ))
160- api .fs .rename_sub = wrap_node (require ( " nvim-tree. actions" ) .fs .rename_file .fn (" :p:h" ))
161- api .fs .rename_basename = wrap_node (require ( " nvim-tree. actions" ) .fs .rename_file .fn (" :t:r" ))
162- api .fs .rename_full = wrap_node (require ( " nvim-tree. actions" ) .fs .rename_file .fn (" :p" ))
159+ api .fs .create = wrap_node_or_nil (actions .fs .create_file .fn )
160+ api .fs .remove = wrap_node (actions .fs .remove_file .fn )
161+ api .fs .trash = wrap_node (actions .fs .trash .fn )
162+ api .fs .rename_node = wrap_node (actions .fs .rename_file .fn (" :t" ))
163+ api .fs .rename = wrap_node (actions .fs .rename_file .fn (" :t" ))
164+ api .fs .rename_sub = wrap_node (actions .fs .rename_file .fn (" :p:h" ))
165+ api .fs .rename_basename = wrap_node (actions .fs .rename_file .fn (" :t:r" ))
166+ api .fs .rename_full = wrap_node (actions .fs .rename_file .fn (" :p" ))
163167 api .fs .cut = wrap_node (wrap_explorer_member (" clipboard" , " cut" ))
164168 api .fs .paste = wrap_node (wrap_explorer_member (" clipboard" , " paste" ))
165169 api .fs .clear_clipboard = wrap_explorer_member (" clipboard" , " clear_clipboard" )
@@ -184,34 +188,34 @@ local function hydrate_post(api)
184188 api .node .open .preview = wrap_node (open_or_expand_or_dir_up (" preview" ))
185189 api .node .open .preview_no_picker = wrap_node (open_or_expand_or_dir_up (" preview_no_picker" ))
186190
187- api .node .show_info_popup = wrap_node (require ( " nvim-tree. actions" ) .node .file_popup .toggle_file_info )
188- api .node .run .cmd = wrap_node (require ( " nvim-tree. actions" ) .node .run_command .run_file_command )
189- api .node .run .system = wrap_node (require ( " nvim-tree. actions" ) .node .system_open .fn )
190-
191- api .node .navigate .sibling .next = wrap_node (require ( " nvim-tree. actions" ) .moves .sibling .fn (" next" ))
192- api .node .navigate .sibling .prev = wrap_node (require ( " nvim-tree. actions" ) .moves .sibling .fn (" prev" ))
193- api .node .navigate .sibling .first = wrap_node (require ( " nvim-tree. actions" ) .moves .sibling .fn (" first" ))
194- api .node .navigate .sibling .last = wrap_node (require ( " nvim-tree. actions" ) .moves .sibling .fn (" last" ))
195- api .node .navigate .parent = wrap_node (require ( " nvim-tree. actions" ) .moves .parent .fn (false ))
196- api .node .navigate .parent_close = wrap_node (require ( " nvim-tree. actions" ) .moves .parent .fn (true ))
197- api .node .navigate .git .next = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " next" , what = " git" }))
198- api .node .navigate .git .next_skip_gitignored = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " next" , what = " git" , skip_gitignored = true }))
199- api .node .navigate .git .next_recursive = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " next" , what = " git" , recurse = true }))
200- api .node .navigate .git .prev = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " prev" , what = " git" }))
201- api .node .navigate .git .prev_skip_gitignored = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " prev" , what = " git" , skip_gitignored = true }))
202- api .node .navigate .git .prev_recursive = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " prev" , what = " git" , recurse = true }))
203- api .node .navigate .diagnostics .next = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " next" , what = " diag" }))
204- api .node .navigate .diagnostics .next_recursive = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " next" , what = " diag" , recurse = true }))
205- api .node .navigate .diagnostics .prev = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " prev" , what = " diag" }))
206- api .node .navigate .diagnostics .prev_recursive = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " prev" , what = " diag" , recurse = true }))
207- api .node .navigate .opened .next = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " next" , what = " opened" }))
208- api .node .navigate .opened .prev = wrap_node (require ( " nvim-tree. actions" ) .moves .item .fn ({ where = " prev" , what = " opened" }))
209-
210- api .node .expand = wrap_node (require ( " nvim-tree. actions" ) .tree .modifiers .expand .node )
211- api .node .collapse = wrap_node (require ( " nvim-tree. actions" ) .tree .modifiers .collapse .node )
212-
213- api .node .buffer .delete = wrap_node (function (node , opts ) require ( " nvim-tree. actions" ) .node .buffer .delete (node , opts ) end )
214- api .node .buffer .wipe = wrap_node (function (node , opts ) require ( " nvim-tree. actions" ) .node .buffer .wipe (node , opts ) end )
191+ api .node .show_info_popup = wrap_node (actions .node .file_popup .toggle_file_info )
192+ api .node .run .cmd = wrap_node (actions .node .run_command .run_file_command )
193+ api .node .run .system = wrap_node (actions .node .system_open .fn )
194+
195+ api .node .navigate .sibling .next = wrap_node (actions .moves .sibling .fn (" next" ))
196+ api .node .navigate .sibling .prev = wrap_node (actions .moves .sibling .fn (" prev" ))
197+ api .node .navigate .sibling .first = wrap_node (actions .moves .sibling .fn (" first" ))
198+ api .node .navigate .sibling .last = wrap_node (actions .moves .sibling .fn (" last" ))
199+ api .node .navigate .parent = wrap_node (actions .moves .parent .fn (false ))
200+ api .node .navigate .parent_close = wrap_node (actions .moves .parent .fn (true ))
201+ api .node .navigate .git .next = wrap_node (actions .moves .item .fn ({ where = " next" , what = " git" }))
202+ api .node .navigate .git .next_skip_gitignored = wrap_node (actions .moves .item .fn ({ where = " next" , what = " git" , skip_gitignored = true }))
203+ api .node .navigate .git .next_recursive = wrap_node (actions .moves .item .fn ({ where = " next" , what = " git" , recurse = true }))
204+ api .node .navigate .git .prev = wrap_node (actions .moves .item .fn ({ where = " prev" , what = " git" }))
205+ api .node .navigate .git .prev_skip_gitignored = wrap_node (actions .moves .item .fn ({ where = " prev" , what = " git" , skip_gitignored = true }))
206+ api .node .navigate .git .prev_recursive = wrap_node (actions .moves .item .fn ({ where = " prev" , what = " git" , recurse = true }))
207+ api .node .navigate .diagnostics .next = wrap_node (actions .moves .item .fn ({ where = " next" , what = " diag" }))
208+ api .node .navigate .diagnostics .next_recursive = wrap_node (actions .moves .item .fn ({ where = " next" , what = " diag" , recurse = true }))
209+ api .node .navigate .diagnostics .prev = wrap_node (actions .moves .item .fn ({ where = " prev" , what = " diag" }))
210+ api .node .navigate .diagnostics .prev_recursive = wrap_node (actions .moves .item .fn ({ where = " prev" , what = " diag" , recurse = true }))
211+ api .node .navigate .opened .next = wrap_node (actions .moves .item .fn ({ where = " next" , what = " opened" }))
212+ api .node .navigate .opened .prev = wrap_node (actions .moves .item .fn ({ where = " prev" , what = " opened" }))
213+
214+ api .node .expand = wrap_node (actions .tree .modifiers .expand .node )
215+ api .node .collapse = wrap_node (actions .tree .modifiers .collapse .node )
216+
217+ api .node .buffer .delete = wrap_node (function (node , opts ) actions .node .buffer .delete (node , opts ) end )
218+ api .node .buffer .wipe = wrap_node (function (node , opts ) actions .node .buffer .wipe (node , opts ) end )
215219
216220 api .tree .reload_git = wrap_explorer (" reload_git" )
217221
@@ -238,6 +242,11 @@ local function hydrate_post(api)
238242
239243 api .map .get_keymap = function () require (" nvim-tree.keymap" ).get_keymap () end
240244 api .map .get_keymap_default = function () require (" nvim-tree.keymap" ).get_keymap_default () end
245+
246+ api .health .hi_test = function () require (" nvim-tree.appearance.hi-test" )() end
247+
248+ -- TODO #3231 this should be OK pre
249+ api .commands .get = function () require (" nvim-tree.commands" ).get () end
241250end
242251
243252--- Hydrates all API functions with concrete implementations.
0 commit comments