Skip to content

Commit 941f11f

Browse files
committed
docs(#3088): extract api/node.lua functions
1 parent 8853151 commit 941f11f

5 files changed

Lines changed: 62 additions & 42 deletions

File tree

doc/nvim-tree-lua.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,105 +2689,127 @@ expand({node}, {opts}) *nvim_tree.api.node.expand()*
26892689

26902690
*nvim_tree.api.node.navigate.diagnostics.next()*
26912691
navigate.diagnostics.next({node})
2692+
Navigate to the next item showing diagnostic status.
26922693

26932694
Parameters: ~
26942695
{node} (`nvim_tree.api.Node?`) directory or file
26952696

26962697
*nvim_tree.api.node.navigate.diagnostics.next_recursive()*
26972698
navigate.diagnostics.next_recursive({node})
2699+
Navigate to the next item showing diagnostic status, recursively. Needs
2700+
|nvim_tree.Config.Diagnostics| {show_on_dirs}
26982701

26992702
Parameters: ~
27002703
{node} (`nvim_tree.api.Node?`) directory or file
27012704

27022705
*nvim_tree.api.node.navigate.diagnostics.prev()*
27032706
navigate.diagnostics.prev({node})
2707+
Navigate to the previous item showing diagnostic status.
27042708

27052709
Parameters: ~
27062710
{node} (`nvim_tree.api.Node?`) directory or file
27072711

27082712
*nvim_tree.api.node.navigate.diagnostics.prev_recursive()*
27092713
navigate.diagnostics.prev_recursive({node})
2714+
Navigate to the previous item showing diagnostic status, recursively.
2715+
Needs |nvim_tree.Config.Diagnostics| {show_on_dirs}
27102716

27112717
Parameters: ~
27122718
{node} (`nvim_tree.api.Node?`) directory or file
27132719

27142720
navigate.git.next({node}) *nvim_tree.api.node.navigate.git.next()*
2721+
Navigate to the next item showing git status.
27152722

27162723
Parameters: ~
27172724
{node} (`nvim_tree.api.Node?`) directory or file
27182725

27192726
*nvim_tree.api.node.navigate.git.next_recursive()*
27202727
navigate.git.next_recursive({node})
2728+
Navigate to the next item showing git status, recursively. Needs
2729+
|nvim_tree.Config.Git| {show_on_dirs}
27212730

27222731
Parameters: ~
27232732
{node} (`nvim_tree.api.Node?`) directory or file
27242733

27252734
*nvim_tree.api.node.navigate.git.next_skip_gitignored()*
27262735
navigate.git.next_skip_gitignored({node})
2736+
Navigate to the next item showing git status, skipping `.gitignore`
27272737

27282738
Parameters: ~
27292739
{node} (`nvim_tree.api.Node?`) directory or file
27302740

27312741
navigate.git.prev({node}) *nvim_tree.api.node.navigate.git.prev()*
2742+
Navigate to the previous item showing git status.
27322743

27332744
Parameters: ~
27342745
{node} (`nvim_tree.api.Node?`) directory or file
27352746

27362747
*nvim_tree.api.node.navigate.git.prev_recursive()*
27372748
navigate.git.prev_recursive({node})
2749+
Navigate to the previous item showing git status, recursively. Needs
2750+
|nvim_tree.Config.Git| {show_on_dirs}
27382751

27392752
Parameters: ~
27402753
{node} (`nvim_tree.api.Node?`) directory or file
27412754

27422755
*nvim_tree.api.node.navigate.git.prev_skip_gitignored()*
27432756
navigate.git.prev_skip_gitignored({node})
2757+
Navigate to the previous item showing git status, skipping `.gitignore`
27442758

27452759
Parameters: ~
27462760
{node} (`nvim_tree.api.Node?`) directory or file
27472761

27482762
*nvim_tree.api.node.navigate.opened.next()*
27492763
navigate.opened.next({node})
2764+
Navigate to the next |bufloaded()| file.
27502765

27512766
Parameters: ~
27522767
{node} (`nvim_tree.api.Node?`) directory or file
27532768

27542769
*nvim_tree.api.node.navigate.opened.prev()*
27552770
navigate.opened.prev({node})
2771+
Navigate to the previous |bufloaded()| file.
27562772

27572773
Parameters: ~
27582774
{node} (`nvim_tree.api.Node?`) directory or file
27592775

27602776
navigate.parent({node}) *nvim_tree.api.node.navigate.parent()*
2777+
Navigate to the parent directory of the node.
27612778

27622779
Parameters: ~
27632780
{node} (`nvim_tree.api.Node?`) directory or file
27642781

27652782
*nvim_tree.api.node.navigate.parent_close()*
27662783
navigate.parent_close({node})
2784+
Navigate to the parent directory of the node, closing it.
27672785

27682786
Parameters: ~
27692787
{node} (`nvim_tree.api.Node?`) directory or file
27702788

27712789
*nvim_tree.api.node.navigate.sibling.first()*
27722790
navigate.sibling.first({node})
2791+
Navigate to the first node in the current node's folder.
27732792

27742793
Parameters: ~
27752794
{node} (`nvim_tree.api.Node?`) directory or file
27762795

27772796
*nvim_tree.api.node.navigate.sibling.last()*
27782797
navigate.sibling.last({node})
2798+
Navigate to the last node in the current node's folder.
27792799

27802800
Parameters: ~
27812801
{node} (`nvim_tree.api.Node?`) directory or file
27822802

27832803
*nvim_tree.api.node.navigate.sibling.next()*
27842804
navigate.sibling.next({node})
2805+
Navigate to the next node in the current node's folder, wraps.
27852806

27862807
Parameters: ~
27872808
{node} (`nvim_tree.api.Node?`) directory or file
27882809

27892810
*nvim_tree.api.node.navigate.sibling.prev()*
27902811
navigate.sibling.prev({node})
2812+
Navigate to the previous node in the current node's folder, wraps.
27912813

27922814
Parameters: ~
27932815
{node} (`nvim_tree.api.Node?`) directory or file

lua/nvim-tree/actions/tree/modifiers/collapse.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626

2727
---Collapse a node, root if nil
2828
---@param node Node?
29-
---@param opts nvim_tree.api.tree.collapse.Opts
29+
---@param opts nvim_tree.api.node.collapse.Opts
3030
local function collapse(node, opts)
3131
local explorer = core.get_explorer()
3232
if not explorer then
@@ -60,7 +60,7 @@ local function collapse(node, opts)
6060
end
6161

6262

63-
---@param opts nvim_tree.api.tree.collapse.Opts|boolean|nil legacy -> opts.keep_buffers
63+
---@param opts nvim_tree.api.node.collapse.Opts|boolean|nil legacy -> opts.keep_buffers
6464
function M.all(opts)
6565
-- legacy arguments
6666
if type(opts) == "boolean" then
@@ -73,7 +73,7 @@ function M.all(opts)
7373
end
7474

7575
---@param node Node
76-
---@param opts nvim_tree.api.tree.collapse.Opts?
76+
---@param opts nvim_tree.api.node.collapse.Opts?
7777
function M.node(node, opts)
7878
collapse(node, opts or {})
7979
end

lua/nvim-tree/actions/tree/modifiers/expand.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ local function gen_iterator(should_descend)
125125
end
126126

127127
---@param node Node?
128-
---@param expand_opts nvim_tree.api.tree.expand.Opts?
128+
---@param expand_opts nvim_tree.api.node.expand.Opts?
129129
local function expand_node(node, expand_opts)
130130
if not node then
131131
return
@@ -141,14 +141,14 @@ end
141141

142142
---Expand the directory node or the root
143143
---@param node Node
144-
---@param expand_opts nvim_tree.api.tree.expand.Opts?
144+
---@param expand_opts nvim_tree.api.node.expand.Opts?
145145
function M.all(node, expand_opts)
146146
expand_node(node and node:as(DirectoryNode) or core.get_explorer(), expand_opts)
147147
end
148148

149149
---Expand the directory node or parent node
150150
---@param node Node
151-
---@param expand_opts nvim_tree.api.tree.expand.Opts?
151+
---@param expand_opts nvim_tree.api.node.expand.Opts?
152152
function M.node(node, expand_opts)
153153
if not node then
154154
return

lua/nvim-tree/api/node.lua

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,120 +42,133 @@ function nvim_tree.api.node.buffer.wipe(node, opts) end
4242
---Collapse the tree under a directory or a file's parent directory.
4343
---
4444
---@param node? nvim_tree.api.Node directory or file
45-
---@param opts? nvim_tree.api.tree.collapse.Opts optional
45+
---@param opts? nvim_tree.api.node.collapse.Opts optional
4646
function nvim_tree.api.node.collapse(node, opts) end
4747

48+
---@class nvim_tree.api.node.collapse.Opts
49+
---@inlinedoc
50+
---
51+
---Do not collapse nodes with open buffers.
52+
---(default: false)
53+
---@field keep_buffers? boolean
54+
4855
---
4956
---Recursively expand all nodes under a directory or a file's parent directory.
5057
---
5158
---@param node? nvim_tree.api.Node directory or file
52-
---@param opts? nvim_tree.api.tree.expand.Opts optional
59+
---@param opts? nvim_tree.api.node.expand.Opts optional
5360
function nvim_tree.api.node.expand(node, opts) end
5461

62+
---@class nvim_tree.api.node.expand.Opts
63+
---@inlinedoc
5564
---
65+
---Return `true` if `node` should be expanded. `expansion_count` is the total number of folders expanded.
66+
---@field expand_until? fun(expansion_count: integer, node: Node): boolean
67+
5668
---
69+
---Navigate to the next item showing diagnostic status.
5770
---
5871
---@param node? nvim_tree.api.Node directory or file
5972
function nvim_tree.api.node.navigate.diagnostics.next(node) end
6073

6174
---
62-
---
75+
---Navigate to the next item showing diagnostic status, recursively. Needs [nvim_tree.Config.Diagnostics] {show_on_dirs}
6376
---
6477
---@param node? nvim_tree.api.Node directory or file
6578
function nvim_tree.api.node.navigate.diagnostics.next_recursive(node) end
6679

6780
---
68-
---
81+
---Navigate to the previous item showing diagnostic status.
6982
---
7083
---@param node? nvim_tree.api.Node directory or file
7184
function nvim_tree.api.node.navigate.diagnostics.prev(node) end
7285

7386
---
74-
---
87+
---Navigate to the previous item showing diagnostic status, recursively. Needs [nvim_tree.Config.Diagnostics] {show_on_dirs}
7588
---
7689
---@param node? nvim_tree.api.Node directory or file
7790
function nvim_tree.api.node.navigate.diagnostics.prev_recursive(node) end
7891

7992
---
80-
---
93+
---Navigate to the next item showing git status.
8194
---
8295
---@param node? nvim_tree.api.Node directory or file
8396
function nvim_tree.api.node.navigate.git.next(node) end
8497

8598
---
86-
---
99+
---Navigate to the next item showing git status, recursively. Needs [nvim_tree.Config.Git] {show_on_dirs}
87100
---
88101
---@param node? nvim_tree.api.Node directory or file
89102
function nvim_tree.api.node.navigate.git.next_recursive(node) end
90103

91104
---
92-
---
105+
---Navigate to the next item showing git status, skipping `.gitignore`
93106
---
94107
---@param node? nvim_tree.api.Node directory or file
95108
function nvim_tree.api.node.navigate.git.next_skip_gitignored(node) end
96109

97110
---
98-
---
111+
---Navigate to the previous item showing git status.
99112
---
100113
---@param node? nvim_tree.api.Node directory or file
101114
function nvim_tree.api.node.navigate.git.prev(node) end
102115

103116
---
104-
---
117+
---Navigate to the previous item showing git status, recursively. Needs [nvim_tree.Config.Git] {show_on_dirs}
105118
---
106119
---@param node? nvim_tree.api.Node directory or file
107120
function nvim_tree.api.node.navigate.git.prev_recursive(node) end
108121

109122
---
110-
---
123+
---Navigate to the previous item showing git status, skipping `.gitignore`
111124
---
112125
---@param node? nvim_tree.api.Node directory or file
113126
function nvim_tree.api.node.navigate.git.prev_skip_gitignored(node) end
114127

115128
---
116-
---
129+
---Navigate to the next [bufloaded()] file.
117130
---
118131
---@param node? nvim_tree.api.Node directory or file
119132
function nvim_tree.api.node.navigate.opened.next(node) end
120133

121134
---
122-
---
135+
---Navigate to the previous [bufloaded()] file.
123136
---
124137
---@param node? nvim_tree.api.Node directory or file
125138
function nvim_tree.api.node.navigate.opened.prev(node) end
126139

127140
---
128-
---
141+
---Navigate to the parent directory of the node.
129142
---
130143
---@param node? nvim_tree.api.Node directory or file
131144
function nvim_tree.api.node.navigate.parent(node) end
132145

133146
---
134-
---
147+
---Navigate to the parent directory of the node, closing it.
135148
---
136149
---@param node? nvim_tree.api.Node directory or file
137150
function nvim_tree.api.node.navigate.parent_close(node) end
138151

139152
---
140-
---
153+
---Navigate to the first node in the current node's folder.
141154
---
142155
---@param node? nvim_tree.api.Node directory or file
143156
function nvim_tree.api.node.navigate.sibling.first(node) end
144157

145158
---
146-
---
159+
---Navigate to the last node in the current node's folder.
147160
---
148161
---@param node? nvim_tree.api.Node directory or file
149162
function nvim_tree.api.node.navigate.sibling.last(node) end
150163

151164
---
152-
---
165+
---Navigate to the next node in the current node's folder, wraps.
153166
---
154167
---@param node? nvim_tree.api.Node directory or file
155168
function nvim_tree.api.node.navigate.sibling.next(node) end
156169

157170
---
158-
---
171+
---Navigate to the previous node in the current node's folder, wraps.
159172
---
160173
---@param node? nvim_tree.api.Node directory or file
161174
function nvim_tree.api.node.navigate.sibling.prev(node) end

lua/nvim-tree/api/tree.lua

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---@meta
22
local nvim_tree = { api = { tree = {} } }
33

4-
-- TODO #3088 move expand/collapse into api.node
5-
64
---
75
---Open the tree, focusing it if already open.
86
---
@@ -177,29 +175,16 @@ function nvim_tree.api.tree.search_node() end
177175
---
178176
---Collapse the tree.
179177
---
180-
---@param opts? nvim_tree.api.tree.collapse.Opts optional
178+
---@param opts? nvim_tree.api.node.collapse.Opts optional
181179
function nvim_tree.api.tree.collapse_all(opts) end
182180

183-
---@class nvim_tree.api.tree.collapse.Opts
184-
---@inlinedoc
185-
---
186-
---Do not collapse nodes with open buffers.
187-
---(default: false)
188-
---@field keep_buffers? boolean
189-
190181
---
191182
---Recursively expand all nodes under the tree root or specified folder.
192183
---
193184
---@param node? nvim_tree.api.Node directory
194-
---@param opts? nvim_tree.api.tree.expand.Opts optional
185+
---@param opts? nvim_tree.api.node.expand.Opts optional
195186
function nvim_tree.api.tree.expand_all(node, opts) end
196187

197-
---@class nvim_tree.api.tree.expand.Opts
198-
---@inlinedoc
199-
---
200-
---Return `true` if `node` should be expanded. `expansion_count` is the total number of folders expanded.
201-
---@field expand_until? fun(expansion_count: integer, node: Node): boolean
202-
203188
---
204189
---Toggle [nvim_tree.Config.Filters] {enable} all filters.
205190
---

0 commit comments

Comments
 (0)