@@ -14,8 +14,55 @@ local FileLinkNode = require("nvim-tree.node.file-link")
1414local RootNode = require (" nvim-tree.node.root" )
1515local UserDecorator = require (" nvim-tree.renderer.decorator.user" )
1616
17- -- hydrates meta api definitions with implementations
18- return function (api )
17+ local M = {}
18+
19+ --- Walk the api, setting all functions to the error notification
20+ --- @param t table
21+ local function hydrate_notify (t )
22+ for k , v in pairs (t ) do
23+ if type (v ) == " function" then
24+ t [k ] = function () notify .error (" nvim-tree setup not called" ) end
25+ elseif type (v ) == " table" then
26+ hydrate_notify (v )
27+ end
28+ end
29+ end
30+
31+ --- Hydrates meta api definition functions with a function.
32+ ---- Default: return "nvim-tree setup not called".
33+ ---- Exceptions: concrete implementation for API that can be called before setup.
34+ --- Call it once when api is first required
35+ --- @param api table
36+ function M .hydrate_init (api )
37+ --
38+ -- Hydrate all with the error function
39+ --
40+ hydrate_notify (api )
41+
42+ --
43+ -- Rehydrate implementations that may be called before setup
44+ --
45+ api .events .subscribe = events .subscribe
46+ api .events .Event = events .Event
47+
48+ api .map .default_on_attach = keymap .default_on_attach
49+
50+ api .decorator = {}
51+ --- Create a decorator class by calling :extend()
52+ --- See :help nvim-tree-decorators
53+ --- @type nvim_tree.api.decorator.UserDecorator
54+ api .decorator .UserDecorator = UserDecorator --[[ @as nvim_tree.api.decorator.UserDecorator]]
55+
56+ --
57+ -- Map legacy to above.
58+ --
59+ require (" nvim-tree.legacy" ).map_api (api )
60+ end
61+
62+ --- Hydrates all API functions with concrete implementations.
63+ --- Call this after nvim-tree setup
64+ --- @param api table
65+ function M .hydrate_after_setup (api )
1966 --- Print error when setup not called.
2067 --- @param fn fun ( ... ): any
2168 --- @return fun ( ... ): any
@@ -253,9 +300,6 @@ return function(api)
253300 api .node .expand = wrap_node (actions .tree .modifiers .expand .node )
254301 api .node .collapse = wrap_node (actions .tree .modifiers .collapse .node )
255302
256- --- @class ApiNodeDeleteWipeBufferOpts
257- --- @field force boolean | nil default false
258-
259303 api .node .buffer .delete = wrap_node (function (node , opts )
260304 actions .node .buffer .delete (node , opts )
261305 end )
@@ -265,9 +309,6 @@ return function(api)
265309
266310 api .tree .reload_git = wrap_explorer (" reload_git" )
267311
268- api .events .subscribe = events .subscribe
269- api .events .Event = events .Event
270-
271312 api .filter .live .start = wrap_explorer_member (" live_filter" , " start_filtering" )
272313 api .filter .live .clear = wrap_explorer_member (" live_filter" , " clear_filter" )
273314 api .filter .toggle = wrap_explorer_member (" filters" , " toggle" )
@@ -291,17 +332,17 @@ return function(api)
291332
292333 api .map .get_keymap = wrap (keymap .get_keymap )
293334 api .map .get_keymap_default = wrap (keymap .get_keymap_default )
294- api .map .default_on_attach = keymap .default_on_attach
295335
296336 api .health .hi_test = wrap (appearance_hi_test )
297337
298338 api .commands .get = wrap (function ()
299339 return require (" nvim-tree.commands" ).get ()
300340 end )
301341
302- api .decorator = {}
303- --- Create a decorator class by calling :extend()
304- --- See :help nvim-tree-decorators
305- --- @type nvim_tree.api.decorator.UserDecorator
306- api .decorator .UserDecorator = UserDecorator --[[ @as nvim_tree.api.decorator.UserDecorator]]
342+ --
343+ -- Remap legacy to above
344+ --
345+ require (" nvim-tree.legacy" ).map_api (api )
307346end
347+
348+ return M
0 commit comments