11--- Hydrates all API functions with concrete implementations.
22--- Replace all "nvim-tree setup not called" error functions from pre.lua with their implementations.
33---
4- --- Call this after nvim-tree setup
5- ---
6- --- All requires must be done lazily so that requiring api post setup is cheap.
7-
8- local legacy = require (" nvim-tree.legacy" )
4+ --- Called after nvim-tree setup
95
106local M = {}
117
12- --- convenience wrappers for lazy module requires
13- local function actions () return require (" nvim-tree.actions" ) end
14- local function core () return require (" nvim-tree.core" ) end
15- local function config () return require (" nvim-tree.config" ) end
16- local function help () return require (" nvim-tree.help" ) end
17- local function keymap () return require (" nvim-tree.keymap" ) end
18- local function utils () return require (" nvim-tree.utils" ) end
19- local function view () return require (" nvim-tree.view" ) end
20-
218--- Return a function wrapper that calls fn.
229--- Injects node or node at cursor as first argument.
2310--- Passes other arguments verbatim.
@@ -26,7 +13,7 @@ local function view() return require("nvim-tree.view") end
2613local function _n (fn )
2714 return function (n , ...)
2815 if not n then
29- local e = core ( ).get_explorer ()
16+ local e = require ( " nvim-tree.core " ).get_explorer ()
3017 n = e and e :get_node_at_cursor () or nil
3118 end
3219 return fn (n , ... )
4128--- @return fun ( e : Explorer , ... ): any
4229local function e_ (fn )
4330 return function (...)
44- local e = core ( ).get_explorer ()
31+ local e = require ( " nvim-tree.core " ).get_explorer ()
4532 if e then
4633 return fn (e , ... )
4734 end
5744--- @return fun ( e : Explorer , n ?: Node , ... ): any
5845local function en (fn )
5946 return function (n , ...)
60- local e = core ( ).get_explorer ()
47+ local e = require ( " nvim-tree.core " ).get_explorer ()
6148 if e then
62- return fn (e , n or e :get_node_at_cursor (), ... )
49+ n = e and e :get_node_at_cursor () or nil
50+ return fn (e , n , ... )
6351 end
6452 end
6553end
7866--- Re-Hydrate api functions and classes post-setup
7967--- @param api table not properly typed to prevent LSP from referencing implementations
8068function M .hydrate (api )
81- api .config .global = __ (function () return config ( ).g_clone () end )
82- api .config .user = __ (function () return config ( ).u_clone () end )
69+ api .config .global = __ (function () return require ( " nvim-tree.config " ).g_clone () end )
70+ api .config .user = __ (function () return require ( " nvim-tree.config " ).u_clone () end )
8371
8472 api .filter .custom .toggle = e_ (function (e ) e .filters :toggle (" custom" ) end )
8573 api .filter .dotfiles .toggle = e_ (function (e ) e .filters :toggle (" dotfiles" ) end )
@@ -97,19 +85,19 @@ function M.hydrate(api)
9785 api .fs .copy .filename = en (function (e , n ) e .clipboard :copy_filename (n ) end )
9886 api .fs .copy .node = en (function (e , n ) e .clipboard :copy (n ) end )
9987 api .fs .copy .relative_path = en (function (e , n ) e .clipboard :copy_path (n ) end )
100- api .fs .create = _n (function (n ) actions ( ).fs .create_file .fn (n ) end )
88+ api .fs .create = _n (function (n ) require ( " nvim-tree.actions " ).fs .create_file .fn (n ) end )
10189 api .fs .cut = en (function (e , n ) e .clipboard :cut (n ) end )
10290 api .fs .paste = en (function (e , n ) e .clipboard :paste (n ) end )
10391 api .fs .print_clipboard = e_ (function (e ) e .clipboard :print_clipboard () end )
104- api .fs .remove = _n (function (n ) actions ( ).fs .remove_file .fn (n ) end )
105- api .fs .rename = _n (function (n ) actions ( ).fs .rename_file .rename_node (n ) end )
106- api .fs .rename_basename = _n (function (n ) actions ( ).fs .rename_file .rename_basename (n ) end )
107- api .fs .rename_full = _n (function (n ) actions ( ).fs .rename_file .rename_full (n ) end )
108- api .fs .rename_node = _n (function (n ) actions ( ).fs .rename_file .rename_node (n ) end )
109- api .fs .rename_sub = _n (function (n ) actions ( ).fs .rename_file .rename_sub (n ) end )
110- api .fs .trash = _n (function (n ) actions ( ).fs .trash .fn (n ) end )
92+ api .fs .remove = _n (function (n ) require ( " nvim-tree.actions " ).fs .remove_file .fn (n ) end )
93+ api .fs .rename = _n (function (n ) require ( " nvim-tree.actions " ).fs .rename_file .rename_node (n ) end )
94+ api .fs .rename_basename = _n (function (n ) require ( " nvim-tree.actions " ).fs .rename_file .rename_basename (n ) end )
95+ api .fs .rename_full = _n (function (n ) require ( " nvim-tree.actions " ).fs .rename_file .rename_full (n ) end )
96+ api .fs .rename_node = _n (function (n ) require ( " nvim-tree.actions " ).fs .rename_file .rename_node (n ) end )
97+ api .fs .rename_sub = _n (function (n ) require ( " nvim-tree.actions " ).fs .rename_file .rename_sub (n ) end )
98+ api .fs .trash = _n (function (n ) require ( " nvim-tree.actions " ).fs .trash .fn (n ) end )
11199
112- api .map .keymap .current = __ (function () return keymap ( ).get_keymap () end )
100+ api .map .keymap .current = __ (function () return require ( " nvim-tree.keymap " ).get_keymap () end )
113101
114102 api .marks .bulk .delete = e_ (function (e ) e .marks :bulk_delete () end )
115103 api .marks .bulk .move = e_ (function (e ) e .marks :bulk_move () end )
@@ -122,70 +110,70 @@ function M.hydrate(api)
122110 api .marks .navigate .select = e_ (function (e ) e .marks :navigate_select () end )
123111 api .marks .toggle = en (function (e , n ) e .marks :toggle (n ) end )
124112
125- api .node .buffer .delete = _n (function (n , opts ) actions ( ).node .buffer .delete (n , opts ) end )
126- api .node .buffer .wipe = _n (function (n , opts ) actions ( ).node .buffer .wipe (n , opts ) end )
127- api .node .collapse = _n (function (n ) actions ( ).tree .collapse .node (n ) end )
113+ api .node .buffer .delete = _n (function (n , opts ) require ( " nvim-tree.actions " ).node .buffer .delete (n , opts ) end )
114+ api .node .buffer .wipe = _n (function (n , opts ) require ( " nvim-tree.actions " ).node .buffer .wipe (n , opts ) end )
115+ api .node .collapse = _n (function (n ) require ( " nvim-tree.actions " ).tree .collapse .node (n ) end )
128116 api .node .expand = en (function (e , n ) e :expand_node (n ) end )
129- api .node .navigate .diagnostics .next = __ (function () actions ( ).moves .item .diagnostics_next () end )
130- api .node .navigate .diagnostics .next_recursive = __ (function () actions ( ).moves .item .diagnostics_next_recursive () end )
131- api .node .navigate .diagnostics .prev = __ (function () actions ( ).moves .item .diagnostics_prev () end )
132- api .node .navigate .diagnostics .prev_recursive = __ (function () actions ( ).moves .item .diagnostics_prev_recursive () end )
133- api .node .navigate .git .next = __ (function () actions ( ).moves .item .git_next () end )
134- api .node .navigate .git .next_recursive = __ (function () actions ( ).moves .item .git_next_recursive () end )
135- api .node .navigate .git .next_skip_gitignored = __ (function () actions ( ).moves .item .git_next_skip_gitignored () end )
136- api .node .navigate .git .prev = __ (function () actions ( ).moves .item .git_prev () end )
137- api .node .navigate .git .prev_recursive = __ (function () actions ( ).moves .item .git_prev_recursive () end )
138- api .node .navigate .git .prev_skip_gitignored = __ (function () actions ( ).moves .item .git_prev_skip_gitignored () end )
139- api .node .navigate .opened .next = __ (function () actions ( ).moves .item .opened_next () end )
140- api .node .navigate .opened .prev = __ (function () actions ( ).moves .item .opened_prev () end )
141- api .node .navigate .parent = _n (function (n ) actions ( ).moves .parent .move (n ) end )
142- api .node .navigate .parent_close = _n (function (n ) actions ( ).moves .parent .move_close (n ) end )
143- api .node .navigate .sibling .first = _n (function (n ) actions ( ).moves .sibling .first (n ) end )
144- api .node .navigate .sibling .last = _n (function (n ) actions ( ).moves .sibling .last (n ) end )
145- api .node .navigate .sibling .next = _n (function (n ) actions ( ).moves .sibling .next (n ) end )
146- api .node .navigate .sibling .prev = _n (function (n ) actions ( ).moves .sibling .prev (n ) end )
147- api .node .open .drop = _n (function (n ) actions ( ).node .open_file .drop (n ) end )
148- api .node .open .edit = _n (function (n ) actions ( ).node .open_file .edit (n ) end )
149- api .node .open .horizontal = _n (function (n ) actions ( ).node .open_file .horizontal (n ) end )
150- api .node .open .horizontal_no_picker = _n (function (n ) actions ( ).node .open_file .horizontal_no_picker (n ) end )
151- api .node .open .no_window_picker = _n (function (n ) actions ( ).node .open_file .no_window_picker (n ) end )
152- api .node .open .preview = _n (function (n ) actions ( ).node .open_file .preview (n ) end )
153- api .node .open .preview_no_picker = _n (function (n ) actions ( ).node .open_file .preview_no_picker (n ) end )
154- api .node .open .replace_tree_buffer = _n (function (n ) actions ( ).node .open_file .replace_tree_buffer (n ) end )
155- api .node .open .tab = _n (function (n ) actions ( ).node .open_file .tab (n ) end )
156- api .node .open .tab_drop = _n (function (n ) actions ( ).node .open_file .tab_drop (n ) end )
157- api .node .open .toggle_group_empty = _n (function (n ) actions ( ).node .open_file .toggle_group_empty (n ) end )
158- api .node .open .vertical = _n (function (n ) actions ( ).node .open_file .vertical (n ) end )
159- api .node .open .vertical_no_picker = _n (function (n ) actions ( ).node .open_file .vertical_no_picker (n ) end )
160- api .node .run .cmd = _n (function (n ) actions ( ).node .run_command .run_file_command (n ) end )
161- api .node .run .system = _n (function (n ) actions ( ).node .system_open .fn (n ) end )
162- api .node .show_info_popup = _n (function (n ) actions ( ).node .file_popup .toggle_file_info (n ) end )
163-
164- api .tree .change_root = __ (function (path ) actions ( ).tree .change_dir .fn (path ) end )
117+ api .node .navigate .diagnostics .next = __ (function () require ( " nvim-tree.actions " ).moves .item .diagnostics_next () end )
118+ api .node .navigate .diagnostics .next_recursive = __ (function () require ( " nvim-tree.actions " ).moves .item .diagnostics_next_recursive () end )
119+ api .node .navigate .diagnostics .prev = __ (function () require ( " nvim-tree.actions " ).moves .item .diagnostics_prev () end )
120+ api .node .navigate .diagnostics .prev_recursive = __ (function () require ( " nvim-tree.actions " ).moves .item .diagnostics_prev_recursive () end )
121+ api .node .navigate .git .next = __ (function () require ( " nvim-tree.actions " ).moves .item .git_next () end )
122+ api .node .navigate .git .next_recursive = __ (function () require ( " nvim-tree.actions " ).moves .item .git_next_recursive () end )
123+ api .node .navigate .git .next_skip_gitignored = __ (function () require ( " nvim-tree.actions " ).moves .item .git_next_skip_gitignored () end )
124+ api .node .navigate .git .prev = __ (function () require ( " nvim-tree.actions " ).moves .item .git_prev () end )
125+ api .node .navigate .git .prev_recursive = __ (function () require ( " nvim-tree.actions " ).moves .item .git_prev_recursive () end )
126+ api .node .navigate .git .prev_skip_gitignored = __ (function () require ( " nvim-tree.actions " ).moves .item .git_prev_skip_gitignored () end )
127+ api .node .navigate .opened .next = __ (function () require ( " nvim-tree.actions " ).moves .item .opened_next () end )
128+ api .node .navigate .opened .prev = __ (function () require ( " nvim-tree.actions " ).moves .item .opened_prev () end )
129+ api .node .navigate .parent = _n (function (n ) require ( " nvim-tree.actions " ).moves .parent .move (n ) end )
130+ api .node .navigate .parent_close = _n (function (n ) require ( " nvim-tree.actions " ).moves .parent .move_close (n ) end )
131+ api .node .navigate .sibling .first = _n (function (n ) require ( " nvim-tree.actions " ).moves .sibling .first (n ) end )
132+ api .node .navigate .sibling .last = _n (function (n ) require ( " nvim-tree.actions " ).moves .sibling .last (n ) end )
133+ api .node .navigate .sibling .next = _n (function (n ) require ( " nvim-tree.actions " ).moves .sibling .next (n ) end )
134+ api .node .navigate .sibling .prev = _n (function (n ) require ( " nvim-tree.actions " ).moves .sibling .prev (n ) end )
135+ api .node .open .drop = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .drop (n ) end )
136+ api .node .open .edit = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .edit (n ) end )
137+ api .node .open .horizontal = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .horizontal (n ) end )
138+ api .node .open .horizontal_no_picker = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .horizontal_no_picker (n ) end )
139+ api .node .open .no_window_picker = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .no_window_picker (n ) end )
140+ api .node .open .preview = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .preview (n ) end )
141+ api .node .open .preview_no_picker = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .preview_no_picker (n ) end )
142+ api .node .open .replace_tree_buffer = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .replace_tree_buffer (n ) end )
143+ api .node .open .tab = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .tab (n ) end )
144+ api .node .open .tab_drop = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .tab_drop (n ) end )
145+ api .node .open .toggle_group_empty = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .toggle_group_empty (n ) end )
146+ api .node .open .vertical = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .vertical (n ) end )
147+ api .node .open .vertical_no_picker = _n (function (n ) require ( " nvim-tree.actions " ).node .open_file .vertical_no_picker (n ) end )
148+ api .node .run .cmd = _n (function (n ) require ( " nvim-tree.actions " ).node .run_command .run_file_command (n ) end )
149+ api .node .run .system = _n (function (n ) require ( " nvim-tree.actions " ).node .system_open .fn (n ) end )
150+ api .node .show_info_popup = _n (function (n ) require ( " nvim-tree.actions " ).node .file_popup .toggle_file_info (n ) end )
151+
152+ api .tree .change_root = __ (function (path ) require ( " nvim-tree.actions " ).tree .change_dir .fn (path ) end )
165153 api .tree .change_root_to_node = en (function (e , n ) e :change_dir_to_node (n ) end )
166154 api .tree .change_root_to_parent = en (function (e , n ) e :dir_up (n ) end )
167- api .tree .close = __ (function () view ( ).close () end )
168- api .tree .close_in_all_tabs = __ (function () view ( ).close_all_tabs () end )
169- api .tree .close_in_this_tab = __ (function () view ( ).close_this_tab_only () end )
170- api .tree .collapse_all = __ (function () actions ( ).tree .collapse .all () end )
155+ api .tree .close = __ (function () require ( " nvim-tree.view " ).close () end )
156+ api .tree .close_in_all_tabs = __ (function () require ( " nvim-tree.view " ).close_all_tabs () end )
157+ api .tree .close_in_this_tab = __ (function () require ( " nvim-tree.view " ).close_this_tab_only () end )
158+ api .tree .collapse_all = __ (function () require ( " nvim-tree.actions " ).tree .collapse .all () end )
171159 api .tree .expand_all = en (function (e , n , opts ) e :expand_all (n , opts ) end )
172- api .tree .find_file = __ (function () actions ( ).tree .find_file .fn () end )
173- api .tree .focus = __ (function () actions ( ).tree .open .fn () end )
160+ api .tree .find_file = __ (function () require ( " nvim-tree.actions " ).tree .find_file .fn () end )
161+ api .tree .focus = __ (function () require ( " nvim-tree.actions " ).tree .open .fn () end )
174162 api .tree .get_node_under_cursor = en (function (e ) return e :get_node_at_cursor () end )
175163 api .tree .get_nodes = en (function (e ) return e :get_nodes () end )
176- api .tree .is_tree_buf = __ (function () return utils ( ).is_nvim_tree_buf () end )
177- api .tree .is_visible = __ (function () return view ( ).is_visible () end )
178- api .tree .open = __ (function () actions ( ).tree .open .fn () end )
164+ api .tree .is_tree_buf = __ (function () return require ( " nvim-tree.utils " ).is_nvim_tree_buf () end )
165+ api .tree .is_visible = __ (function () return require ( " nvim-tree.view " ).is_visible () end )
166+ api .tree .open = __ (function () require ( " nvim-tree.actions " ).tree .open .fn () end )
179167 api .tree .reload = e_ (function (e ) e :reload_explorer () end )
180168 api .tree .reload_git = e_ (function (e ) e :reload_git () end )
181- api .tree .resize = __ (function () actions ( ).tree .resize .fn () end )
182- api .tree .search_node = __ (function () actions ( ).finders .search_node .fn () end )
183- api .tree .toggle = __ (function () actions ( ).tree .toggle .fn () end )
184- api .tree .toggle_help = __ (function () help ( ).toggle () end )
185- api .tree .winid = __ (function () return view ( ).winid () end )
169+ api .tree .resize = __ (function () require ( " nvim-tree.actions " ).tree .resize .fn () end )
170+ api .tree .search_node = __ (function () require ( " nvim-tree.actions " ).finders .search_node .fn () end )
171+ api .tree .toggle = __ (function () require ( " nvim-tree.actions " ).tree .toggle .fn () end )
172+ api .tree .toggle_help = __ (function () require ( " nvim-tree.help " ).toggle () end )
173+ api .tree .winid = __ (function () return require ( " nvim-tree.view " ).winid () end )
186174
187175 -- (Re)hydrate any legacy by mapping to concrete set above
188- legacy .map_api (api )
176+ require ( " nvim-tree. legacy" ) .map_api (api )
189177end
190178
191179return M
0 commit comments