Skip to content

Commit 9e6ce3a

Browse files
committed
docs(#3088): document node and git classes, namespace internal and external git classes, redact node subclasses
1 parent b3e8a63 commit 9e6ce3a

17 files changed

Lines changed: 194 additions & 223 deletions

File tree

doc/nvim-tree-lua.txt

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,72 +2389,42 @@ e.g. the following are functionally identical: >lua
23892389
<
23902390

23912391

2392-
2393-
2394-
2395-
Base Node class:
2396-
2397-
23982392
*nvim_tree.api.Node*
2399-
Base Node, Abstract
2400-
2401-
Fields: ~
2402-
{type} (`"file"|"directory"|"link"`) uv.fs_stat.result.type
2403-
• {absolute_path} (`string`)
2404-
{executable} (`boolean`)
2405-
• {fs_stat}? (`uv.fs_stat.result`)
2406-
• {git_status}? (`GitNodeStatus`)
2407-
{hidden} (`boolean`)
2408-
{name} (`string`)
2409-
{parent}? (`nvim_tree.api.DirectoryNode`)
2410-
• {diag_severity}? (`lsp.DiagnosticSeverity`)
2411-
2412-
2413-
2414-
2415-
2416-
Node subclasses:
2417-
2393+
The Node class is a data class. Instances may be provided by API functions
2394+
for use as a:
2395+
• handle to pass back to API functions e.g. |nvim_tree.api.node.run.cmd()|
2396+
• reference in callbacks e.g. |nvim_tree.config.sort.Sorter| {sorter}
24182397

2419-
*nvim_tree.api.DirectoryLinkNode*
2420-
Extends: |nvim_tree.api.DirectoryNode|
2421-
2422-
DirectoryLink
2423-
2424-
*nvim_tree.api.DirectoryNode*
2425-
Extends: |nvim_tree.api.Node|
2426-
2427-
Directory
2428-
2429-
Fields: ~
2430-
• {has_children} (`boolean`)
2431-
{nodes} (`nvim_tree.api.Node[]`)
2432-
{open} (`boolean`)
2433-
2434-
*nvim_tree.api.FileLinkNode*
2435-
Extends: |nvim_tree.api.FileNode|
2436-
2437-
File Link
2438-
2439-
*nvim_tree.api.FileNode*
2440-
Extends: |nvim_tree.api.Node|
2441-
2442-
File
2398+
Please do not mutate the contents of any Node object.
24432399

24442400
Fields: ~
2445-
{extension} (`string`)
2446-
2447-
*nvim_tree.api.LinkNode*
2448-
Link mixin
2401+
{type} (`"file"|"directory"|"link"`) see |uv.fs_stat()|
2402+
{type}
2403+
• {absolute_path} (`string`) of the file or directory
2404+
{executable} (`boolean`) file is executable
2405+
• {fs_stat}? (`uv.fs_stat.result`) at time of last tree display,
2406+
see |uv.fs_stat()|
2407+
• {git_status} (`nvim_tree.git.Status?`) for files and directories
2408+
{hidden} (`boolean`) node is not visible in the tree
2409+
{name} (`string`) file or directory name
2410+
{parent}? (`nvim_tree.api.DirectoryNode`) parent directory,
2411+
nil for root
2412+
• {diag_severity}? (`lsp.DiagnosticSeverity`) diagnostic status
2413+
2414+
*nvim_tree.git.Status*
2415+
Git statuses for a single node.
2416+
2417+
`nvim_tree.git.XY`: 2 character string, see `man 1 git-status` "Short
2418+
Format"
2419+
2420+
{dir} status is derived from its contents:
2421+
`direct`: inherited from child files
2422+
`indirect`: inherited from child directories
24492423

24502424
Fields: ~
2451-
• {link_to} (`string`)
2452-
• {fs_stat_target} (`uv.fs_stat.result`)
2453-
2454-
*nvim_tree.api.RootNode*
2455-
Extends: |nvim_tree.api.DirectoryNode|
2456-
2457-
Root Directory
2425+
{file}? (`nvim_tree.git.XY`) status of a file node
2426+
{dir}? (`table<"direct"|"indirect", nvim_tree.git.XY[]>`) direct
2427+
inclusive-or indirect status
24582428

24592429

24602430

lua/nvim-tree/_meta/api.lua

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---@meta
2+
error("Cannot require a meta file")
3+
4+
---@brief
5+
---nvim-tree exposes a public API. This is non breaking, with additions made as necessary.
6+
---
7+
---Please do not require or use modules other than `nvim-tree.api`, as internal modules will change without notice.
8+
---
9+
---The API is separated into multiple modules:
10+
---
11+
---- [nvim-tree-api-commands]
12+
---- [nvim-tree-api-events]
13+
---- [nvim-tree-api-filter]
14+
---- [nvim-tree-api-fs]
15+
---- [nvim-tree-api-health]
16+
---- [nvim-tree-api-map]
17+
---- [nvim-tree-api-marks]
18+
---- [nvim-tree-api-node]
19+
---- [nvim-tree-api-tree]
20+
---
21+
---Modules are accessed via `api.<module>.<function>`
22+
---
23+
---Example invocation of the `reload` function in the `tree` module:
24+
---```lua
25+
---
26+
---local api = require("nvim-tree.api")
27+
---api.tree.reload()
28+
---```
29+
---Generally, functions accepting a [nvim_tree.api.Node] as their first argument will use the node under the cursor when that argument is not present or nil. e.g. the following are functionally identical:
30+
---```lua
31+
---
32+
---api.node.open.edit(nil, { focus = true })
33+
---
34+
---api.node.open.edit(api.tree.get_node_under_cursor(), { focus = true })
35+
---```
36+
37+
38+
---The Node class is a data class. Instances may be provided by API functions for use as a:
39+
---- handle to pass back to API functions e.g. [nvim_tree.api.node.run.cmd()]
40+
---- reference in callbacks e.g. [nvim_tree.config.sort.Sorter] {sorter}
41+
---
42+
---Please do not mutate the contents of any Node object.
43+
---
44+
---@class nvim_tree.api.Node
45+
---@field absolute_path string of the file or directory
46+
---@field name string file or directory name
47+
---@field parent? nvim_tree.api.DirectoryNode parent directory, nil for root
48+
---@field type "file" | "directory" | "link" [uv.fs_stat()] {type}
49+
---@field executable boolean file is executable
50+
---@field fs_stat? uv.fs_stat.result at time of last tree display, see [uv.fs_stat()]
51+
---@field git_status nvim_tree.git.Status? for files and directories
52+
---@field diag_severity? lsp.DiagnosticSeverity diagnostic status
53+
---@field hidden boolean node is not visible in the tree
54+
55+
56+
---
57+
---Git statuses for a single node.
58+
---
59+
---`nvim_tree.git.XY`: 2 character string, see `man 1 git-status` "Short Format"
60+
---@alias nvim_tree.git.XY string
61+
---
62+
---{dir} status is derived from its contents:
63+
---- `direct`: inherited from child files
64+
---- `indirect`: inherited from child directories
65+
---
66+
---@class nvim_tree.git.Status
67+
---@field file? nvim_tree.git.XY status of a file node
68+
---@field dir? table<"direct" | "indirect", nvim_tree.git.XY[]> direct inclusive-or indirect status
69+
70+
71+
72+
73+
-- Following are exact as that prevents them from having documentation generated.
74+
-- They are not ready for public exposure as:
75+
-- - They are not classic classes
76+
-- - They are only used in a few locations: api.tree.get_nodes and UserDecorator
77+
78+
---
79+
---File
80+
---
81+
---@class (exact) nvim_tree.api.FileNode: nvim_tree.api.Node
82+
---@field extension string
83+
84+
---
85+
---Directory
86+
---
87+
---@class (exact) nvim_tree.api.DirectoryNode: nvim_tree.api.Node
88+
---@field has_children boolean
89+
---@field nodes nvim_tree.api.Node[]
90+
---@field open boolean
91+
92+
---
93+
---Root Directory
94+
---
95+
---@class (exact) nvim_tree.api.RootNode: nvim_tree.api.DirectoryNode
96+
97+
---
98+
---Link mixin
99+
---
100+
---@class (exact) nvim_tree.api.LinkNode
101+
---@field link_to string
102+
---@field fs_stat_target uv.fs_stat.result
103+
104+
---
105+
---File Link
106+
---
107+
---@class (exact) nvim_tree.api.FileLinkNode: nvim_tree.api.FileNode, nvim_tree.api.LinkNode
108+
109+
---
110+
---DirectoryLink
111+
---
112+
---@class (exact) nvim_tree.api.DirectoryLinkNode: nvim_tree.api.DirectoryNode, nvim_tree.api.LinkNode

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

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

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

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

lua/nvim-tree/api.lua

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
11
local api = {}
22

3-
---@brief
4-
---nvim-tree exposes a public API. This is non breaking, with additions made as necessary.
5-
---
6-
---Please do not require or use modules other than `nvim-tree.api`, as internal modules will change without notice.
7-
---
8-
---The API is separated into multiple modules:
9-
---
10-
---- [nvim-tree-api-commands]
11-
---- [nvim-tree-api-events]
12-
---- [nvim-tree-api-filter]
13-
---- [nvim-tree-api-fs]
14-
---- [nvim-tree-api-health]
15-
---- [nvim-tree-api-map]
16-
---- [nvim-tree-api-marks]
17-
---- [nvim-tree-api-node]
18-
---- [nvim-tree-api-tree]
19-
---
20-
---Modules are accessed via `api.<module>.<function>`
21-
---
22-
---Example invocation of the `reload` function in the `tree` module:
23-
---```lua
24-
---
25-
---local api = require("nvim-tree.api")
26-
---api.tree.reload()
27-
---```
28-
---Generally, functions accepting a [nvim_tree.api.Node] as their first argument will use the node under the cursor when that argument is not present or nil. e.g. the following are functionally identical:
29-
---```lua
30-
---
31-
---api.node.open.edit(nil, { focus = true })
32-
---
33-
---api.node.open.edit(api.tree.get_node_under_cursor(), { focus = true })
34-
---```
35-
36-
373
--
384
-- Load the (empty) meta definitions
395
--
@@ -47,7 +13,6 @@ api.marks = require("nvim-tree._meta.api.marks")
4713
api.node = require("nvim-tree._meta.api.node")
4814
api.tree = require("nvim-tree._meta.api.tree")
4915

50-
5116
--
5217
-- Map implementations
5318
--

lua/nvim-tree/explorer/filters.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
---Check if the given path is git clean/ignored
6666
---@private
6767
---@param path string Absolute path
68-
---@param project GitProject from prepare
68+
---@param project nvim_tree.git.Project from prepare
6969
---@return boolean
7070
function Filters:git(path, project)
7171
if type(project) ~= "table" or type(project.files) ~= "table" or type(project.dirs) ~= "table" then
@@ -193,7 +193,7 @@ function Filters:custom(path)
193193
end
194194

195195
---Prepare arguments for should_filter. This is done prior to should_filter for efficiency reasons.
196-
---@param project GitProject? optional results of git.load_projects(...)
196+
---@param project nvim_tree.git.Project? optional results of git.load_projects(...)
197197
---@return table
198198
--- project: reference
199199
--- bufinfo: empty unless no_buffer set: vim.fn.getbufinfo { buflisted = 1 }

lua/nvim-tree/explorer/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function Explorer:expand_dir_node(node)
200200
end
201201

202202
---@param node DirectoryNode
203-
---@param project GitProject?
203+
---@param project nvim_tree.git.Project?
204204
---@return Node[]?
205205
function Explorer:reload(node, project)
206206
local cwd = node.link_to or node.absolute_path
@@ -358,7 +358,7 @@ end
358358
---@private
359359
---@param nodes_by_path Node[]
360360
---@param node_ignored boolean
361-
---@param project GitProject?
361+
---@param project nvim_tree.git.Project?
362362
---@return fun(node: Node): Node
363363
function Explorer:update_git_statuses(nodes_by_path, node_ignored, project)
364364
return function(node)
@@ -373,7 +373,7 @@ end
373373
---@param handle uv.uv_fs_t
374374
---@param cwd string
375375
---@param node DirectoryNode
376-
---@param project GitProject
376+
---@param project nvim_tree.git.Project
377377
---@param parent Explorer
378378
function Explorer:populate_children(handle, cwd, node, project, parent)
379379
local node_ignored = node:is_git_ignored()
@@ -432,7 +432,7 @@ end
432432

433433
---@private
434434
---@param node DirectoryNode
435-
---@param project GitProject
435+
---@param project nvim_tree.git.Project
436436
---@param parent Explorer
437437
---@return Node[]|nil
438438
function Explorer:explore(node, project, parent)
@@ -467,7 +467,7 @@ function Explorer:explore(node, project, parent)
467467
end
468468

469469
---@private
470-
---@param projects GitProject[]
470+
---@param projects nvim_tree.git.Project[]
471471
function Explorer:refresh_nodes(projects)
472472
Iterator.builder({ self })
473473
:applier(function(n)

0 commit comments

Comments
 (0)