Skip to content

Commit c6c5286

Browse files
committed
docs(#3088): move legacy api into api.impl.legacy, fixes following testing
1 parent a675266 commit c6c5286

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

lua/nvim-tree/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ local api = {
8282
events = require("nvim-tree._meta.api.events"),
8383
filter = require("nvim-tree._meta.api.filter"),
8484
fs = require("nvim-tree._meta.api.fs"),
85-
git = require("nvim-tree._meta.api._git"),
85+
git = require("nvim-tree._meta.api.git"),
8686
health = require("nvim-tree._meta.api.health"),
8787
map = require("nvim-tree._meta.api.map"),
8888
marks = require("nvim-tree._meta.api.marks"),

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---Silently create new api entries pointing legacy functions to current
2+
---@param api table not properly typed to prevent LSP from referencing implementations
3+
return function(api)
4+
api.config = api.config or {}
5+
api.config.mappings = api.config.mappings or {}
6+
api.config.mappings.get_keymap = api.map.keymap.current
7+
api.config.mappings.get_keymap_default = api.map.keymap.default
8+
api.config.mappings.default_on_attach = api.map.on_attach.default
9+
10+
api.live_filter = api.live_filter or {}
11+
api.live_filter.start = api.filter.live.start
12+
api.live_filter.clear = api.filter.live.clear
13+
14+
api.tree = api.tree or {}
15+
api.tree.toggle_enable_filters = api.filter.toggle
16+
api.tree.toggle_gitignore_filter = api.filter.git.ignored.toggle
17+
api.tree.toggle_git_clean_filter = api.filter.git.clean.toggle
18+
api.tree.toggle_no_buffer_filter = api.filter.no_buffer.toggle
19+
api.tree.toggle_custom_filter = api.filter.custom.toggle
20+
api.tree.toggle_hidden_filter = api.filter.dotfiles.toggle
21+
api.tree.toggle_no_bookmark_filter = api.filter.no_bookmark.toggle
22+
23+
api.diagnostics = api.diagnostics or {}
24+
api.diagnostics.hi_test = api.health.hi_test
25+
end

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
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 view = require("nvim-tree.view")
109
local actions = require("nvim-tree.actions")
10+
local help = require("nvim-tree.help")
11+
local keymap = require("nvim-tree.keymap")
12+
local utils = require("nvim-tree.utils")
13+
local view = require("nvim-tree.view")
1114

1215
local DirectoryNode = require("nvim-tree.node.directory")
1316
local FileLinkNode = require("nvim-tree.node.file-link")
@@ -131,7 +134,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
131134
end
132135

133136
---Hydrate all implementations barring those that were called during hydrate_pre
134-
---@param api table
137+
---@param api table not properly typed to prevent LSP from referencing implementations
135138
local function hydrate_post(api)
136139
api.tree.open = actions.tree.open.fn
137140
api.tree.focus = api.tree.open
@@ -157,8 +160,8 @@ local function hydrate_post(api)
157160
api.tree.collapse_all = actions.tree.collapse.all
158161

159162
api.tree.expand_all = wrap_node(wrap_explorer("expand_all"))
160-
api.tree.toggle_help = function() require("nvim-tree.help").toggle() end
161-
api.tree.is_tree_buf = function() require("nvim-tree.utils").is_nvim_tree_buf() end
163+
api.tree.toggle_help = help.toggle
164+
api.tree.is_tree_buf = utils.is_nvim_tree_buf
162165

163166
api.tree.is_visible = view.is_visible
164167

@@ -248,15 +251,15 @@ local function hydrate_post(api)
248251
api.marks.navigate.prev = wrap_explorer_member("marks", "navigate_prev")
249252
api.marks.navigate.select = wrap_explorer_member("marks", "navigate_select")
250253

251-
api.map.get_keymap = function() require("nvim-tree.keymap").get_keymap() end
254+
api.map.keymap.current = keymap.get_keymap
252255
end
253256

254257
---Re-hydrate api
255-
---@param api table
258+
---@param api table not properly typed to prevent LSP from referencing implementations
256259
return function(api)
257260
-- All concrete implementations
258261
hydrate_post(api)
259262

260263
-- (Re)hydrate any legacy by mapping to function set above
261-
require("nvim-tree.legacy").api_map(api)
264+
require("nvim-tree.api.impl.legacy")(api)
262265
end

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ local function hydrate_error(t)
3030
end
3131

3232
---Hydrate implementations that may be called pre setup
33+
---@param api table not properly typed to prevent LSP from referencing implementations
3334
local function hydrate_pre(api)
3435
--
3536
-- Essential
@@ -51,7 +52,7 @@ local function hydrate_pre(api)
5152
--
5253
api.commands.get = commands.get
5354

54-
api.map.get_keymap_default = keymap.get_keymap_default
55+
api.map.keymap.default = keymap.get_keymap_default
5556

5657

5758
--
@@ -65,6 +66,7 @@ local function hydrate_pre(api)
6566
end
6667

6768
---Hydrate api
69+
---@param api table not properly typed to prevent LSP from referencing implementations
6870
return function(api)
6971
-- Default: error
7072
hydrate_error(api)
@@ -73,5 +75,5 @@ return function(api)
7375
hydrate_pre(api)
7476

7577
-- Hydrate any legacy by mapping to function set above
76-
require("nvim-tree.legacy").api_map(api)
78+
require("nvim-tree.api.impl.legacy")(api)
7779
end

lua/nvim-tree/legacy.lua

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ local notify = require("nvim-tree.notify")
22

33
local M = {}
44

5-
--
6-
--Functions
7-
--
8-
95
--- Create empty sub-tables if not present
106
---@param tbl table to create empty inside of
117
---@param path string dot separated string of sub-tables
@@ -54,10 +50,6 @@ local function move(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
5450
end
5551
end
5652

57-
--
58-
--Config
59-
--
60-
6153
-- silently move, please add to help nvim-tree-legacy-opts
6254
local function refactored(opts)
6355
-- 2022/06/20
@@ -159,33 +151,4 @@ function M.migrate_legacy_options(opts)
159151
removed(opts)
160152
end
161153

162-
--
163-
--API
164-
--
165-
166-
---Silently create new api entries pointing legacy functions to current
167-
function M.api_map(api)
168-
api.config = api.config or {}
169-
api.config.mappings = api.config.mappings or {}
170-
api.config.mappings.get_keymap = api.map.keymap.current
171-
api.config.mappings.get_keymap_default = api.map.keymap.default
172-
api.config.mappings.default_on_attach = api.map.on_attach.default
173-
174-
api.live_filter = api.live_filter or {}
175-
api.live_filter.start = api.filter.live.start
176-
api.live_filter.clear = api.filter.live.clear
177-
178-
api.tree = api.tree or {}
179-
api.tree.toggle_enable_filters = api.filter.toggle
180-
api.tree.toggle_gitignore_filter = api.filter.git.ignored.toggle
181-
api.tree.toggle_git_clean_filter = api.filter.git.clean.toggle
182-
api.tree.toggle_no_buffer_filter = api.filter.no_buffer.toggle
183-
api.tree.toggle_custom_filter = api.filter.custom.toggle
184-
api.tree.toggle_hidden_filter = api.filter.dotfiles.toggle
185-
api.tree.toggle_no_bookmark_filter = api.filter.no_bookmark.toggle
186-
187-
api.diagnostics = api.diagnostics or {}
188-
api.diagnostics.hi_test = api.health.hi_test
189-
end
190-
191154
return M

scripts/gen_vimdoc_config.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
--Returned config is injected into the above.
33
--See gen_vimdoc.sh
44

5+
--gen_vimdoc keys by filename: -- FIXME: Using f_base will confuse `_meta/protocol.lua` with `protocol.lua`
6+
--Hence we must ensure that filenames are unique within each nvim.gen_vimdoc.Config[]
7+
58
---@class (exact) Src
69
---@field helptag string must be globally unique
710
---@field section string arbitrary
@@ -37,7 +40,7 @@ local srcs_config = {
3740

3841
{ helptag = "nvim-tree-config-default", section = "Config: Default", path = pre .. "_meta/config/default.lua", },
3942

40-
{ helptag = "nvim-tree-api", section = "API Placeholder", path = pre .. "api.lua", },
43+
{ helptag = "nvim-tree-api", section = "placeholder for next Config", path = pre .. "api.lua", },
4144
}
4245

4346
---@type Src[]
@@ -89,7 +92,7 @@ local function src_by_name(name, srcs)
8992
error(string.format("\n\nPath for lower, extension stripped file name='%s' not found in\nsrcs=%s\n", name, vim.inspect(srcs)))
9093
end
9194

92-
-- @type table<string,nvim.gen_vimdoc.Config>
95+
-- @type nvim.gen_vimdoc.Config[]
9396
return {
9497
-- Config
9598
{

0 commit comments

Comments
 (0)