Skip to content

Commit dfeeb12

Browse files
authored
refactor(#3255): all API is lazily loaded (#3287)
* refactor(#3255): wire node.navigate.sibling API impl directly to functions * refactor(#3255): wire fs.rename API impl directly to functions * refactor(#3255): wire node.navigate.parent API impl directly to functions * refactor(#3255): wire remaining node.navigate API impl directly to functions * refactor(#3255): wire node.open API impl directly to functions, move edit and open_or_expand_or_dir_up to open-file * refactor(#3255): wire tree.change_root API impl directly to a function in new action module change-dir * refactor(#3255): lazy post requires, split into formatted groups * refactor(#3255): all post are lazy * refactor(#3255): all post are wrapped consistently * refactor(#3255): all pre are lazy * refactor(#3255): move Event to meta * refactor(#3255): ensure all args passed to api * refactor(#3255): ensure all args passed to api, fix incorrectly documented api interface * refactor(#3255): ensure all args passed to api, fix incorrectly documented api interface * refactor(#3255): ensure all args passed to api * refactor(#3255): add visual mode wrappers * refactor(#3255): define @enum nvim_tree.api.events.Event * refactor(#3255): merge api pre and post * refactor(#3255): merge api pre and post * refactor(#3255): merge api pre and post
1 parent e16cd38 commit dfeeb12

18 files changed

Lines changed: 708 additions & 631 deletions

File tree

doc/nvim-tree-lua.txt

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ subscribe({event_type}, {callback}) *nvim_tree.api.events.subscribe()*
24202420
Register a handler for an event, see |nvim-tree-events|.
24212421

24222422
Parameters: ~
2423-
• {event_type} (`string`) |nvim_tree_events_kind|
2423+
• {event_type} (`nvim_tree.api.events.Event`) |nvim_tree_events_kind|
24242424
{callback} (`fun(payload: table?)`)
24252425

24262426

@@ -2616,9 +2616,12 @@ bulk.trash() *nvim_tree.api.marks.bulk.trash()*
26162616
clear() *nvim_tree.api.marks.clear()*
26172617
Clear all marks.
26182618

2619-
get() *nvim_tree.api.marks.get()*
2619+
get({node}) *nvim_tree.api.marks.get()*
26202620
Return the node if it is marked.
26212621

2622+
Parameters: ~
2623+
{node} (`nvim_tree.api.Node?`) file or directory
2624+
26222625
Return: ~
26232626
(`nvim_tree.api.Node?`)
26242627

@@ -2828,64 +2831,39 @@ open.edit({node}, {opts}) *nvim_tree.api.node.open.edit()*
28282831
{focus}? (`boolean`, default: false) Keep focus in the tree
28292832
when opening the file.
28302833

2831-
open.horizontal({node}, {opts}) *nvim_tree.api.node.open.horizontal()*
2834+
open.horizontal({node}) *nvim_tree.api.node.open.horizontal()*
28322835
Open file in a new horizontal split.
28332836

28342837
Parameters: ~
28352838
{node} (`nvim_tree.api.Node?`) file
2836-
{opts} (`table?`) optional
2837-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2838-
when opening the file.
2839-
{focus}? (`boolean`, default: false) Keep focus in the tree
2840-
when opening the file.
28412839

28422840
*nvim_tree.api.node.open.horizontal_no_picker()*
2843-
open.horizontal_no_picker({node}, {opts})
2841+
open.horizontal_no_picker({node})
28442842
Open file in a new horizontal split without using the window picker.
28452843

28462844
Parameters: ~
28472845
{node} (`nvim_tree.api.Node?`) file
2848-
{opts} (`table?`) optional
2849-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2850-
when opening the file.
2851-
{focus}? (`boolean`, default: false) Keep focus in the tree
2852-
when opening the file.
28532846

28542847
*nvim_tree.api.node.open.no_window_picker()*
2855-
open.no_window_picker({node}, {opts})
2848+
open.no_window_picker({node})
28562849
Open file without using the window picker.
28572850

28582851
Parameters: ~
28592852
{node} (`nvim_tree.api.Node?`) file
2860-
{opts} (`table?`) optional
2861-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2862-
when opening the file.
2863-
{focus}? (`boolean`, default: false) Keep focus in the tree
2864-
when opening the file.
28652853

2866-
open.preview({node}, {opts}) *nvim_tree.api.node.open.preview()*
2854+
open.preview({node}) *nvim_tree.api.node.open.preview()*
28672855
Open file with |'bufhidden'| set to `delete`.
28682856

28692857
Parameters: ~
28702858
{node} (`nvim_tree.api.Node?`) directory or file
2871-
{opts} (`table?`) optional
2872-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2873-
when opening the file.
2874-
{focus}? (`boolean`, default: false) Keep focus in the tree
2875-
when opening the file.
28762859

28772860
*nvim_tree.api.node.open.preview_no_picker()*
2878-
open.preview_no_picker({node}, {opts})
2861+
open.preview_no_picker({node})
28792862
Open file with |'bufhidden'| set to `delete` without using the window
28802863
picker.
28812864

28822865
Parameters: ~
28832866
{node} (`nvim_tree.api.Node?`) directory or file
2884-
{opts} (`table?`) optional
2885-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2886-
when opening the file.
2887-
{focus}? (`boolean`, default: false) Keep focus in the tree
2888-
when opening the file.
28892867

28902868
*nvim_tree.api.node.open.replace_tree_buffer()*
28912869
open.replace_tree_buffer({node})
@@ -2894,16 +2872,11 @@ open.replace_tree_buffer({node})
28942872
Parameters: ~
28952873
{node} (`nvim_tree.api.Node?`) file
28962874

2897-
open.tab({node}, {opts}) *nvim_tree.api.node.open.tab()*
2875+
open.tab({node}) *nvim_tree.api.node.open.tab()*
28982876
Open file in a new tab.
28992877

29002878
Parameters: ~
29012879
{node} (`nvim_tree.api.Node?`) directory or file
2902-
{opts} (`table?`) optional
2903-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2904-
when opening the file.
2905-
{focus}? (`boolean`, default: false) Keep focus in the tree
2906-
when opening the file.
29072880

29082881
open.tab_drop({node}) *nvim_tree.api.node.open.tab_drop()*
29092882
Switch to tab containing window with selected file if it exists. Open file
@@ -2913,40 +2886,25 @@ open.tab_drop({node}) *nvim_tree.api.node.open.tab_drop()*
29132886
{node} (`nvim_tree.api.Node?`) directory or file
29142887

29152888
*nvim_tree.api.node.open.toggle_group_empty()*
2916-
open.toggle_group_empty({node}, {opts})
2889+
open.toggle_group_empty({node})
29172890
Toggle |nvim_tree.config.renderer| {group_empty} for a directory. Needs
29182891
{group_empty} set.
29192892

29202893
Parameters: ~
29212894
{node} (`nvim_tree.api.Node?`) directory
2922-
{opts} (`table?`) optional
2923-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2924-
when opening the file.
2925-
{focus}? (`boolean`, default: false) Keep focus in the tree
2926-
when opening the file.
29272895

2928-
open.vertical({node}, {opts}) *nvim_tree.api.node.open.vertical()*
2896+
open.vertical({node}) *nvim_tree.api.node.open.vertical()*
29292897
Open file in a new vertical split.
29302898

29312899
Parameters: ~
29322900
{node} (`nvim_tree.api.Node?`) file
2933-
{opts} (`table?`) optional
2934-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2935-
when opening the file.
2936-
{focus}? (`boolean`, default: false) Keep focus in the tree
2937-
when opening the file.
29382901

29392902
*nvim_tree.api.node.open.vertical_no_picker()*
2940-
open.vertical_no_picker({node}, {opts})
2903+
open.vertical_no_picker({node})
29412904
Open file in a new vertical split without using the window picker.
29422905

29432906
Parameters: ~
29442907
{node} (`nvim_tree.api.Node?`) file
2945-
{opts} (`table?`) optional
2946-
• {quit_on_open}? (`boolean`, default: false) Quits the tree
2947-
when opening the file.
2948-
{focus}? (`boolean`, default: false) Keep focus in the tree
2949-
when opening the file.
29502908

29512909
run.cmd({node}) *nvim_tree.api.node.run.cmd()*
29522910
Enter |cmdline| with the full path of the node and the cursor at the start

lua/nvim-tree.lua

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,6 @@ local function manage_netrw()
141141
end
142142
end
143143

144-
---@param name string|nil
145-
function M.change_dir(name)
146-
if name then
147-
explorer_fn("change_dir", name)
148-
end
149-
150-
if config.g.update_focused_file.update_root.enable then
151-
actions.tree.find_file.fn()
152-
end
153-
end
154-
155144
local function setup_autocommands()
156145
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true })
157146
local function create_nvim_tree_autocmd(name, custom_opts)
@@ -180,7 +169,7 @@ local function setup_autocommands()
180169
if config.g.sync_root_with_cwd then
181170
create_nvim_tree_autocmd("DirChanged", {
182171
callback = function()
183-
M.change_dir(vim.loop.cwd())
172+
actions.tree.change_dir.fn(vim.loop.cwd())
184173
end,
185174
})
186175
end
@@ -320,7 +309,7 @@ function M.setup(config_user)
320309
vim.g.NvimTreeSetup = 1
321310
vim.api.nvim_exec_autocmds("User", { pattern = "NvimTreeSetup" })
322311

323-
require("nvim-tree.api.impl.post").hydrate(api)
312+
require("nvim-tree.api.impl").hydrate_post_setup(api)
324313
end
325314

326315
vim.g.NvimTreeRequired = 1

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
---@meta
22
local nvim_tree = { api = { events = {} } }
33

4+
---@enum nvim_tree.api.events.Event
5+
nvim_tree.api.events.Event = {
6+
Ready = "Ready",
7+
WillRenameNode = "WillRenameNode",
8+
NodeRenamed = "NodeRenamed",
9+
TreePreOpen = "TreePreOpen",
10+
TreeOpen = "TreeOpen",
11+
TreeClose = "TreeClose",
12+
WillCreateFile = "WillCreateFile",
13+
FileCreated = "FileCreated",
14+
WillRemoveFile = "WillRemoveFile",
15+
FileRemoved = "FileRemoved",
16+
FolderCreated = "FolderCreated",
17+
FolderRemoved = "FolderRemoved",
18+
Resize = "Resize",
19+
TreeAttachedPost = "TreeAttachedPost",
20+
TreeRendered = "TreeRendered",
21+
}
22+
423
---
524
---Register a handler for an event, see [nvim-tree-events].
625
---
7-
---@param event_type string [nvim_tree_events_kind]
26+
---@param event_type nvim_tree.api.events.Event [nvim_tree_events_kind]
827
---@param callback fun(payload: table?)
928
function nvim_tree.api.events.subscribe(event_type, callback) end
1029

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ local nvim_tree = { api = { marks = {} } }
44
---
55
---Return the node if it is marked.
66
---
7+
---@param node? nvim_tree.api.Node file or directory
78
---@return nvim_tree.api.Node?
8-
function nvim_tree.api.marks.get() end
9+
function nvim_tree.api.marks.get(node) end
910

1011
---
1112
---Retrieve all marked nodes.

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,31 @@ function nvim_tree.api.node.open.edit(node, opts) end
2929
---Open file in a new horizontal split.
3030
---
3131
---@param node? nvim_tree.api.Node file
32-
---@param opts? nvim_tree.api.node.open.Opts optional
33-
function nvim_tree.api.node.open.horizontal(node, opts) end
32+
function nvim_tree.api.node.open.horizontal(node) end
3433

3534
---
3635
---Open file in a new horizontal split without using the window picker.
3736
---
3837
---@param node? nvim_tree.api.Node file
39-
---@param opts? nvim_tree.api.node.open.Opts optional
40-
function nvim_tree.api.node.open.horizontal_no_picker(node, opts) end
38+
function nvim_tree.api.node.open.horizontal_no_picker(node) end
4139

4240
---
4341
---Open file without using the window picker.
4442
---
4543
---@param node? nvim_tree.api.Node file
46-
---@param opts? nvim_tree.api.node.open.Opts optional
47-
function nvim_tree.api.node.open.no_window_picker(node, opts) end
44+
function nvim_tree.api.node.open.no_window_picker(node) end
4845

4946
---
5047
---Open file with ['bufhidden'] set to `delete`.
5148
---
5249
---@param node? nvim_tree.api.Node directory or file
53-
---@param opts? nvim_tree.api.node.open.Opts optional
54-
function nvim_tree.api.node.open.preview(node, opts) end
50+
function nvim_tree.api.node.open.preview(node) end
5551

5652
---
5753
---Open file with ['bufhidden'] set to `delete` without using the window picker.
5854
---
5955
---@param node? nvim_tree.api.Node directory or file
60-
---@param opts? nvim_tree.api.node.open.Opts optional
61-
function nvim_tree.api.node.open.preview_no_picker(node, opts) end
56+
function nvim_tree.api.node.open.preview_no_picker(node) end
6257

6358
---
6459
---Open file in place: in the nvim-tree window.
@@ -70,8 +65,7 @@ function nvim_tree.api.node.open.replace_tree_buffer(node) end
7065
---Open file in a new tab.
7166
---
7267
---@param node? nvim_tree.api.Node directory or file
73-
---@param opts? nvim_tree.api.node.open.Opts optional
74-
function nvim_tree.api.node.open.tab(node, opts) end
68+
function nvim_tree.api.node.open.tab(node) end
7569

7670
---
7771
---Switch to tab containing window with selected file if it exists. Open file in new tab otherwise.
@@ -83,22 +77,19 @@ function nvim_tree.api.node.open.tab_drop(node) end
8377
---Toggle [nvim_tree.config.renderer] {group_empty} for a directory. Needs {group_empty} set.
8478
---
8579
---@param node? nvim_tree.api.Node directory
86-
---@param opts? nvim_tree.api.node.open.Opts optional
87-
function nvim_tree.api.node.open.toggle_group_empty(node, opts) end
80+
function nvim_tree.api.node.open.toggle_group_empty(node) end
8881

8982
---
9083
---Open file in a new vertical split.
9184
---
9285
---@param node? nvim_tree.api.Node file
93-
---@param opts? nvim_tree.api.node.open.Opts optional
94-
function nvim_tree.api.node.open.vertical(node, opts) end
86+
function nvim_tree.api.node.open.vertical(node) end
9587

9688
---
9789
---Open file in a new vertical split without using the window picker.
9890
---
9991
---@param node? nvim_tree.api.Node file
100-
---@param opts? nvim_tree.api.node.open.Opts optional
101-
function nvim_tree.api.node.open.vertical_no_picker(node, opts) end
92+
function nvim_tree.api.node.open.vertical_no_picker(node) end
10293

10394
---
10495
---@class nvim_tree.api.node.buffer.RemoveOpts

0 commit comments

Comments
 (0)