Skip to content

Commit 6a867ff

Browse files
committed
doc(#2934): add nvim_tree.Config meta classes, add nvim_tree.api. meta classes
1 parent 0395699 commit 6a867ff

12 files changed

Lines changed: 490 additions & 68 deletions

File tree

lua/nvim-tree.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ local ACCEPTED_ENUMS = {
621621
},
622622
}
623623

624-
---@param conf table|nil
624+
---@param conf? nvim_tree.Config
625625
local function validate_options(conf)
626626
local msg
627627

@@ -726,7 +726,7 @@ function M.purge_all_state()
726726
require("nvim-tree.watcher").purge_watchers()
727727
end
728728

729-
---@param conf table|nil
729+
---@param conf? nvim_tree.Config
730730
function M.setup(conf)
731731
if vim.fn.has("nvim-0.9") == 0 then
732732
notify.warn("nvim-tree.lua requires Neovim 0.9 or higher")

lua/nvim-tree/_meta/api.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
---@meta
22
error("Cannot require a meta file")
33

4+
--
5+
-- API Options
6+
--
7+
8+
---@class nvim_tree.api.TreeOpenOpts
9+
---@field path? string root directory for the tree
10+
---@field current_window? boolean open the tree in the current window
11+
---@field winid? number open the tree in the specified winid, overrides current_window
12+
---@field find_file? boolean find the current buffer
13+
---@field update_root? boolean requires find_file, see |nvim-tree.update_focused_file.update_root|
14+
---@field focus? boolean focus the tree when opening, default true
15+
16+
---@class nvim_tree.api.TreeToggleOpts
17+
---@field path? string root directory for the tree
18+
---@field current_window? boolean open the tree in the current window
19+
---@field winid? number open the tree in the specified |winid|, overrides current_window
20+
---@field find_file? boolean find the current buffer
21+
---@field update_root? boolean requires find_file, see |nvim-tree.update_focused_file.update_root|
22+
---@field focus? boolean focus the tree when opening, default true
23+
24+
---@class nvim_tree.api.TreeResizeOpts
25+
---@field width? string|function|number|table new |nvim-tree.view.width| value
26+
---@field absolute? number set the width
27+
---@field relative? number relative width adjustment
28+
29+
---@class nvim_tree.api.TreeFindFileOpts
30+
---@field buf? string|number absolute/relative path OR bufnr to find
31+
---@field open? boolean open the tree if necessary
32+
---@field current_window? boolean requires open, open in the current window
33+
---@field winid? number open the tree in the specified |winid|, overrides current_window
34+
---@field update_root? boolean see |nvim-tree.update_focused_file.update_root|
35+
---@field focus? boolean focus the tree
36+
37+
---@class nvim_tree.api.CollapseOpts
38+
---@field keep_buffers? boolean do not collapse nodes with open buffers
39+
40+
---@class nvim_tree.api.TreeExpandOpts
41+
---@field expand_until? (fun(expansion_count: integer, node: Node): boolean) Return true if node should be expanded. expansion_count is the total number of folders expanded.
42+
43+
---@class nvim_tree.api.TreeIsVisibleOpts
44+
---@field tabpage? number as per |nvim_get_current_tabpage()|
45+
---@field any_tabpage? boolean visible on any tab, default false
46+
47+
---@class nvim_tree.api.TreeWinIdOpts
48+
---@field tabpage? number tabpage, 0 or nil for current, default nil
49+
50+
---@class nvim_tree.api.NodeEditOpts
51+
---@field quit_on_open? boolean quits the tree when opening the file
52+
---@field focus? boolean keep focus in the tree when opening the file
53+
54+
---@class nvim_tree.api.NodeBufferOpts
55+
---@field force? boolean delete/wipe even if buffer is modified, default false
56+
457
--
558
-- Nodes
659
--

lua/nvim-tree/_meta/config.lua

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

lua/nvim-tree/actions/node/buffer.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ local notify = require("nvim-tree.notify")
44
local M = {}
55

66
---@param node Node
7-
---@param opts ApiNodeDeleteWipeBufferOpts|nil
7+
---@param opts nvim_tree.api.NodeBufferOpts|nil
88
---@return nil
99
function M.delete(node, opts)
1010
M.delete_buffer("delete", node.absolute_path, opts)
1111
end
1212

1313
---@param node Node
14-
---@param opts ApiNodeDeleteWipeBufferOpts|nil
14+
---@param opts nvim_tree.api.NodeBufferOpts|nil
1515
---@return nil
1616
function M.wipe(node, opts)
1717
M.delete_buffer("wipe", node.absolute_path, opts)
@@ -21,7 +21,7 @@ end
2121

2222
---@param mode ApiNodeDeleteWipeBufferMode
2323
---@param filename string
24-
---@param opts ApiNodeDeleteWipeBufferOpts|nil
24+
---@param opts nvim_tree.api.NodeBufferOpts|nil
2525
---@return nil
2626
function M.delete_buffer(mode, filename, opts)
2727
if type(mode) ~= "string" then

lua/nvim-tree/actions/tree/find-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local finders_find_file = require("nvim-tree.actions.finders.find-file")
66
local M = {}
77

88
--- Find file or buffer
9-
---@param opts ApiTreeFindFileOpts|nil|boolean legacy -> opts.buf
9+
---@param opts nvim_tree.api.TreeFindFileOpts|nil|boolean legacy -> opts.buf
1010
function M.fn(opts)
1111
-- legacy arguments
1212
if type(opts) == "string" then

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 ApiCollapseOpts
29+
---@param opts nvim_tree.api.CollapseOpts
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 ApiCollapseOpts|boolean|nil legacy -> opts.keep_buffers
63+
---@param opts nvim_tree.api.CollapseOpts|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 ApiCollapseOpts?
76+
---@param opts nvim_tree.api.CollapseOpts?
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 ApiTreeExpandOpts?
128+
---@param expand_opts nvim_tree.api.TreeExpandOpts?
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 ApiTreeExpandOpts?
144+
---@param expand_opts nvim_tree.api.TreeExpandOpts?
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 ApiTreeExpandOpts?
151+
---@param expand_opts nvim_tree.api.TreeExpandOpts?
152152
function M.node(node, expand_opts)
153153
if not node then
154154
return

lua/nvim-tree/actions/tree/open.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local finders_find_file = require("nvim-tree.actions.finders.find-file")
55
local M = {}
66

77
---Open the tree, focusing if already open.
8-
---@param opts ApiTreeOpenOpts|nil|string legacy -> opts.path
8+
---@param opts nvim_tree.api.TreeOpenOpts|nil|string legacy -> opts.path
99
function M.fn(opts)
1010
-- legacy arguments
1111
if type(opts) == "string" then

lua/nvim-tree/actions/tree/resize.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local view = require("nvim-tree.view")
33
local M = {}
44

55
---Resize the tree, persisting the new size.
6-
---@param opts ApiTreeResizeOpts|nil
6+
---@param opts nvim_tree.api.TreeResizeOpts|nil
77
function M.fn(opts)
88
if opts == nil then
99
-- reset to config values

lua/nvim-tree/actions/tree/toggle.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local finders_find_file = require("nvim-tree.actions.finders.find-file")
55
local M = {}
66

77
---Toggle the tree.
8-
---@param opts ApiTreeToggleOpts|nil|boolean legacy -> opts.find_file
8+
---@param opts nvim_tree.api.TreeToggleOpts|nil|boolean legacy -> opts.find_file
99
---@param no_focus string|nil legacy -> opts.focus
1010
---@param cwd boolean|nil legacy -> opts.path
1111
---@param bang boolean|nil legacy -> opts.update_root

0 commit comments

Comments
 (0)