Skip to content

Commit 49b0b80

Browse files
committed
docs(#3088): minimise api pre following tests
1 parent 728e851 commit 49b0b80

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

lua/nvim-tree/_meta/api/events.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ local nvim_tree = { api = { events = {} } }
88
---@param callback fun(payload: table?)
99
function nvim_tree.api.events.subscribe(event_type, callback) end
1010

11-
nvim_tree.api.events.Event = require("nvim-tree.events").Event
12-
1311
return nvim_tree.api.events

lua/nvim-tree/api/impl/post.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ local function hydrate_post(api)
241241
api.marks.navigate.select = wrap_explorer_member("marks", "navigate_select")
242242

243243
api.map.get_keymap = function() require("nvim-tree.keymap").get_keymap() end
244-
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
250244
end
251245

252246
---Hydrates all API functions with concrete implementations.

lua/nvim-tree/api/impl/pre.lua

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
1-
local events = require("nvim-tree.events")
2-
local keymap = require("nvim-tree.keymap")
3-
local notify = require("nvim-tree.notify")
1+
--This file should have minimal requires that are cheap and have no dependencies or are already required.
2+
--Everything must be as lazily loaded as possible: the user must be able to require api cheaply.
43

5-
local UserDecorator = require("nvim-tree.renderer.decorator.user")
4+
local commands = require("nvim-tree.commands") -- already required by plugin.lua
5+
local events = require("nvim-tree.events") -- needed for event registration pre-setup
6+
local keymap = require("nvim-tree.keymap") -- needed for default on attach
7+
local notify = require("nvim-tree.notify") -- already required by events and others
8+
9+
local UserDecorator = require("nvim-tree.renderer.decorator.user") -- TODO #3241
610

711
---Walk the api, hydrating all functions with the error notification
812
---@param t table api root or sub-module
9-
local function hydrate_notify(t)
13+
local function hydrate_error(t)
1014
for k, v in pairs(t) do
1115
if type(v) == "function" then
1216
t[k] = function()
1317
notify.error("nvim-tree setup not called")
1418
end
1519
elseif type(v) == "table" then
16-
hydrate_notify(v)
20+
hydrate_error(v)
1721
end
1822
end
1923
end
2024

2125
---Hydrate implementations that may be called pre setup
2226
---@param api table
2327
local function hydrate_pre(api)
24-
api.events.subscribe = events.subscribe
28+
--
29+
-- May be lazily requried on execution
30+
--
31+
api.health.hi_test = function() require("nvim-tree.appearance.hi-test")() end
32+
33+
--
34+
-- Essential or already required elsewhere
35+
--
36+
api.commands.get = commands.get
37+
2538
api.events.Event = events.Event
39+
api.events.subscribe = events.subscribe
2640

2741
api.map.default_on_attach = keymap.default_on_attach
42+
api.map.get_keymap_default = keymap.get_keymap_default
2843

2944
api.decorator = {}
3045
---Create a decorator class by calling :extend()
@@ -36,15 +51,11 @@ end
3651
--Hydrates meta api empty definition functions with a new function:
3752
-- - Default: error notification "nvim-tree setup not called".
3853
-- - Exceptions: concrete implementation for API that can be called before setup.
39-
--
4054
--Call it once when api is first required
41-
--
42-
--This should not include any requires beyond that which is absolutely essential,
43-
--as the user should be able to require api cheaply.
4455
---@param api table
4556
return function(api)
4657
-- Default: error
47-
hydrate_notify(api)
58+
hydrate_error(api)
4859

4960
-- Exceptions: may be called
5061
hydrate_pre(api)

0 commit comments

Comments
 (0)