|
1 | 1 | ---Hydrates API meta functions with their implementations. |
2 | | ----For performance reasons, all implementation requires must be done at API call time, not when this module is required. |
| 2 | +---For startup performance reasons, all API implementation's requires must be |
| 3 | +---done at call time, not when this module is required. |
3 | 4 |
|
4 | 5 | local M = {} |
5 | 6 |
|
| 7 | +---Walk the entire API, hydrating all functions with the error notification. |
| 8 | +---Do not hydrate classes i.e. anything with a metatable. |
| 9 | +---@param api table not properly typed to prevent LSP from referencing implementations |
| 10 | +local function hydrate_not_setup(api) |
| 11 | + for k, v in pairs(api) do |
| 12 | + if type(v) == "function" then |
| 13 | + api[k] = function() |
| 14 | + require("nvim-tree.notify").error("nvim-tree setup not called") |
| 15 | + end |
| 16 | + elseif type(v) == "table" and not getmetatable(v) then |
| 17 | + hydrate_not_setup(v) |
| 18 | + end |
| 19 | + end |
| 20 | +end |
| 21 | + |
6 | 22 | ---Returns the node under the cursor. |
7 | 23 | ---@return Node? |
8 | 24 | local function node_at_cursor() |
@@ -90,29 +106,14 @@ local function __(fn) |
90 | 106 | end |
91 | 107 | end |
92 | 108 |
|
93 | | ---Hydrates meta api empty definitions pre-setup: |
94 | | --- - Pre-setup functions will be hydrated with their implementation. |
95 | | --- - Post-setup functions will notify error: "nvim-tree setup not called" |
96 | | --- - All classes will be hydrated with their implementations. |
97 | | ---Called once when api is first required |
| 109 | +---Hydrates API meta functions pre-setup: |
| 110 | +--- Pre-setup functions will be hydrated with their implementation. |
| 111 | +--- Post-setup functions will notify error: "nvim-tree setup not called" |
| 112 | +--- All classes will be hydrated with their implementations. |
| 113 | +---Called once when api is first required |
| 114 | +---@param api table not properly typed to prevent LSP from referencing implementations |
98 | 115 | function M.hydrate_pre_setup(api) |
99 | | - |
100 | | - ---Walk the api, hydrating all functions with the error notification. |
101 | | - ---Do not hydrate classes: anything with a metatable. |
102 | | - ---@param t table |
103 | | - local function hydrate_error(t) |
104 | | - for k, v in pairs(t) do |
105 | | - if type(v) == "function" then |
106 | | - t[k] = function() |
107 | | - require("nvim-tree.notify").error("nvim-tree setup not called") |
108 | | - end |
109 | | - elseif type(v) == "table" and not getmetatable(v) then |
110 | | - hydrate_error(v) |
111 | | - end |
112 | | - end |
113 | | - end |
114 | | - |
115 | | - hydrate_error(api) |
| 116 | + hydrate_not_setup(api) |
116 | 117 |
|
117 | 118 | api.appearance.hi_test = __(function() require("nvim-tree.appearance.hi-test")() end) |
118 | 119 |
|
|
0 commit comments