Skip to content

Commit 8785496

Browse files
committed
docs(#3241): tidy
1 parent 3d1a172 commit 8785496

6 files changed

Lines changed: 40 additions & 37 deletions

File tree

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
---This is expensive as there are many cascading requires and is avoided
77
---until after setup has been called, so that the user may require API cheaply.
88

9+
local legacy = require("nvim-tree.legacy")
10+
911
local actions = require("nvim-tree.actions")
1012
local help = require("nvim-tree.help")
1113
local keymap = require("nvim-tree.keymap")
@@ -256,7 +258,7 @@ function M.hydrate(api)
256258
api.map.keymap.current = keymap.get_keymap
257259

258260
-- (Re)hydrate any legacy by mapping to concrete set above
259-
require("nvim-tree.api.impl.legacy").hydrate(api)
261+
legacy.map_api(api)
260262
end
261263

262264
return M

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
--
1010
--Everything must be as lazily loaded as possible: the user must be able to require api cheaply.
1111

12+
local legacy = require("nvim-tree.legacy")
13+
1214
local commands = require("nvim-tree.commands") -- already required by plugin.lua
1315
local events = require("nvim-tree.events") -- needed for event registration pre-setup
1416
local keymap = require("nvim-tree.keymap") -- needed for default on attach
@@ -40,7 +42,6 @@ function M.hydrate(api)
4042
hydrate_error(api)
4143

4244
-- eager functions
43-
api.events.Event = events.Event
4445
api.events.subscribe = events.subscribe
4546
api.map.on_attach.default = keymap.on_attach_default
4647
api.commands.get = commands.get
@@ -51,9 +52,10 @@ function M.hydrate(api)
5152

5253
-- classes
5354
api.Decorator = Decorator:extend()
55+
api.events.Event = events.Event
5456

5557
-- Hydrate any legacy by mapping to concrete set above
56-
require("nvim-tree.api.impl.legacy").hydrate(api)
58+
legacy.map_api(api)
5759
end
5860

5961
return M

lua/nvim-tree/legacy.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,32 @@ function M.migrate_legacy_options(opts)
151151
removed(opts)
152152
end
153153

154+
---Silently create new api entries pointing legacy functions to current
155+
---@param api table not properly typed to prevent LSP from referencing implementations
156+
function M.map_api(api)
157+
api.config = api.config or {}
158+
api.config.mappings = api.config.mappings or {}
159+
api.config.mappings.get_keymap = api.map.keymap.current
160+
api.config.mappings.get_keymap_default = api.map.keymap.default
161+
api.config.mappings.default_on_attach = api.map.on_attach.default
162+
163+
api.live_filter = api.live_filter or {}
164+
api.live_filter.start = api.filter.live.start
165+
api.live_filter.clear = api.filter.live.clear
166+
167+
api.tree = api.tree or {}
168+
api.tree.toggle_enable_filters = api.filter.toggle
169+
api.tree.toggle_gitignore_filter = api.filter.git.ignored.toggle
170+
api.tree.toggle_git_clean_filter = api.filter.git.clean.toggle
171+
api.tree.toggle_no_buffer_filter = api.filter.no_buffer.toggle
172+
api.tree.toggle_custom_filter = api.filter.custom.toggle
173+
api.tree.toggle_hidden_filter = api.filter.dotfiles.toggle
174+
api.tree.toggle_no_bookmark_filter = api.filter.no_bookmark.toggle
175+
176+
api.diagnostics = api.diagnostics or {}
177+
api.diagnostics.hi_test = api.health.hi_test
178+
179+
api.decorator.UserDecorator = api.Decorator
180+
end
181+
154182
return M

lua/nvim-tree/renderer/decorator/builtin.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Decorator = require("nvim-tree.renderer.decorator")
22

3-
---Builtin decorator interface.
3+
---Abstract builtin decorator
44
---Overrides all methods to use a Node instead of nvim_tree.api.Node as we don't have generics.
55
---
66
---@class (exact) BuiltinDecorator: Decorator

lua/nvim-tree/renderer/decorator/init.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
local DecoratorInterface = require("nvim-tree._meta.api.decorator")
2+
13
---
2-
---Abstract decorator implementation
4+
---Abstract decorator
35
---
46
---@class (exact) Decorator: nvim_tree.api.Decorator
5-
local Decorator = require("nvim-tree._meta.api.decorator"):extend()
7+
local Decorator = DecoratorInterface:extend()
68

79
---Maybe highlight groups for icon and name
810
---@param node nvim_tree.api.Node

0 commit comments

Comments
 (0)