|
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. |
4 | 3 |
|
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 |
6 | 10 |
|
7 | 11 | ---Walk the api, hydrating all functions with the error notification |
8 | 12 | ---@param t table api root or sub-module |
9 | | -local function hydrate_notify(t) |
| 13 | +local function hydrate_error(t) |
10 | 14 | for k, v in pairs(t) do |
11 | 15 | if type(v) == "function" then |
12 | 16 | t[k] = function() |
13 | 17 | notify.error("nvim-tree setup not called") |
14 | 18 | end |
15 | 19 | elseif type(v) == "table" then |
16 | | - hydrate_notify(v) |
| 20 | + hydrate_error(v) |
17 | 21 | end |
18 | 22 | end |
19 | 23 | end |
20 | 24 |
|
21 | 25 | ---Hydrate implementations that may be called pre setup |
22 | 26 | ---@param api table |
23 | 27 | 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 | + |
25 | 38 | api.events.Event = events.Event |
| 39 | + api.events.subscribe = events.subscribe |
26 | 40 |
|
27 | 41 | api.map.default_on_attach = keymap.default_on_attach |
| 42 | + api.map.get_keymap_default = keymap.get_keymap_default |
28 | 43 |
|
29 | 44 | api.decorator = {} |
30 | 45 | ---Create a decorator class by calling :extend() |
|
36 | 51 | --Hydrates meta api empty definition functions with a new function: |
37 | 52 | -- - Default: error notification "nvim-tree setup not called". |
38 | 53 | -- - Exceptions: concrete implementation for API that can be called before setup. |
39 | | --- |
40 | 54 | --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. |
44 | 55 | ---@param api table |
45 | 56 | return function(api) |
46 | 57 | -- Default: error |
47 | | - hydrate_notify(api) |
| 58 | + hydrate_error(api) |
48 | 59 |
|
49 | 60 | -- Exceptions: may be called |
50 | 61 | hydrate_pre(api) |
|
0 commit comments