Skip to content

Commit 060455e

Browse files
committed
docs(#3088): extract api/config/mappings.lua
1 parent 10be08b commit 060455e

File tree

8 files changed

+104
-61
lines changed

8 files changed

+104
-61
lines changed

doc/nvim-tree-lua.txt

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,32 +1079,6 @@ marks.navigate.select() *nvim-tree-api.marks.navigate.select()*
10791079
Prompts for selection of a marked node, sorted by absolute paths.
10801080
A folder will be focused, a file will be opened.
10811081

1082-
==============================================================================
1083-
API: Config *nvim-tree-api.config*
1084-
1085-
*nvim-tree-api.config.mappings.default_on_attach()*
1086-
config.mappings.default_on_attach({bufnr})
1087-
Set all |nvim-tree-mappings-default|. Call from your |nvim_tree.Config| {on_attach}
1088-
1089-
Parameters: ~
1090-
{bufnr} (number) nvim-tree buffer number passed to |nvim_tree.Config| {on_attach}
1091-
1092-
*nvim-tree-api.config.mappings.get_keymap()*
1093-
config.mappings.get_keymap()
1094-
Retrieves all buffer local mappings for nvim-tree.
1095-
These are the mappings that are applied by |nvim_tree.Config| {on_attach}, which
1096-
may include default mappings.
1097-
1098-
Return: ~
1099-
(table) as per |nvim_buf_get_keymap()|
1100-
1101-
*nvim-tree-api.config.mappings.get_keymap_default()*
1102-
config.mappings.get_keymap_default()
1103-
Retrieves the buffer local mappings for nvim-tree that are applied by
1104-
|nvim-tree-api.config.mappings.default_on_attach()|
1105-
1106-
Return: ~
1107-
(table) as per |nvim_buf_get_keymap()|
11081082

11091083
==============================================================================
11101084
API: Commands *nvim-tree-api.commands*
@@ -1266,7 +1240,7 @@ You are encouraged to copy these to your {on_attach} function. >lua
12661240
-- END_DEFAULT_ON_ATTACH
12671241
<
12681242
Alternatively, you may apply these default mappings from your |nvim_tree.Config| {on_attach} via
1269-
|nvim-tree-api.config.mappings.default_on_attach()| e.g. >lua
1243+
|nvim_tree.api.config.mappings.default_on_attach()| e.g. >lua
12701244

12711245
local function my_on_attach(bufnr)
12721246
local api = require("nvim-tree.api")
@@ -2865,6 +2839,34 @@ Class: Config.Log *nvim-tree-config-log*
28652839

28662840

28672841

2842+
==============================================================================
2843+
Lua module: nvim_tree.api.config *nvim-tree-api-config*
2844+
2845+
*nvim_tree.api.config.mappings.default_on_attach()*
2846+
default_on_attach({bufnr})
2847+
Apply all |nvim-tree-mappings-default|. Call from your |nvim_tree.Config|
2848+
{on_attach}.
2849+
2850+
Parameters: ~
2851+
{bufnr} (`integer`) use the `bufnr` passed to {on_attach}
2852+
2853+
get_keymap() *nvim_tree.api.config.mappings.get_keymap()*
2854+
Retrieve all buffer local mappings for nvim-tree. These are the mappings
2855+
that are applied by |nvim_tree.Config| {on_attach}, which may include
2856+
default mappings.
2857+
2858+
Return: ~
2859+
(`vim.api.keyset.get_keymap[]`)
2860+
2861+
*nvim_tree.api.config.mappings.get_keymap_default()*
2862+
get_keymap_default()
2863+
Retrieves the buffer local mappings for nvim-tree that are applied by
2864+
|nvim_tree.api.config.mappings.default_on_attach()|
2865+
2866+
Return: ~
2867+
(`vim.api.keyset.get_keymap[]`)
2868+
2869+
28682870
==============================================================================
28692871
Lua module: nvim_tree.api.tree *nvim-tree-api-tree*
28702872

@@ -2922,14 +2924,14 @@ find_file({opts}) *nvim_tree.api.tree.find_file()*
29222924

29232925
Parameters: ~
29242926
{opts} (`table?`) optional
2925-
{buf}? (`string|number`) Absolute/relative path OR |bufnr()|
2927+
{buf}? (`string|integer`) Absolute/relative path OR `bufnr`
29262928
to find.
29272929
{open}? (`boolean`, default: false) Open the tree if
29282930
necessary.
29292931
• {current_window}? (`boolean`, default: false) Requires
29302932
{open}: open in the current window.
2931-
{winid}? (`number`) Open the tree in the specified |winid|,
2932-
overrides {current_window}
2933+
{winid}? (`integer`) Open the tree in the specified
2934+
|window-ID|, overrides {current_window}
29332935
• {update_root}? (`boolean`, default: false) Update root after
29342936
find, see |nvim_tree.Config.UpdateFocusedFile| {update_root}
29352937
{focus}? (`boolean`, default: false) Focus the tree window.
@@ -2954,7 +2956,7 @@ is_tree_buf({bufnr}) *nvim_tree.api.tree.is_tree_buf()*
29542956
Checks if a buffer is an nvim-tree.
29552957

29562958
Parameters: ~
2957-
{bufnr} (`number?`) 0 or nil for current buffer.
2959+
{bufnr} (`integer?`) 0 or nil for current buffer.
29582960

29592961
Return: ~
29602962
(`boolean`)
@@ -2979,8 +2981,8 @@ open({opts}) *nvim_tree.api.tree.open()*
29792981
{path}? (`string`) Root directory for the tree
29802982
• {current_window}? (`boolean`, default: false) Open the tree
29812983
in the current window
2982-
{winid}? (`number`) Open the tree in the specified |winid|,
2983-
overrides {current_window}
2984+
{winid}? (`integer`) Open the tree in the specified
2985+
|window-ID|, overrides {current_window}
29842986
• {find_file}? (`boolean`, default: false) Find the current
29852987
buffer.
29862988
• {update_root}? (`boolean`, default: false) Update root
@@ -3005,8 +3007,8 @@ resize({opts}) *nvim_tree.api.tree.resize()*
30053007
{width}
30063008
(`nvim_tree.Config.View.WidthSpec|nvim_tree.Config.View.Width`)
30073009
New |nvim_tree.Config.View| {width} value.
3008-
{absolute} (`number`) Set the width.
3009-
{relative} (`number`) Increase or decrease the width.
3010+
{absolute} (`integer`) Set the width.
3011+
{relative} (`integer`) Increase or decrease the width.
30103012

30113013
search_node() *nvim_tree.api.tree.search_node()*
30123014
Open the search dialogue.
@@ -3019,8 +3021,8 @@ toggle({opts}) *nvim_tree.api.tree.toggle()*
30193021
{path}? (`string`) Root directory for the tree
30203022
• {current_window}? (`boolean`, default: false) Open the tree
30213023
in the current window
3022-
{winid}? (`number`) Open the tree in the specified |winid|,
3023-
overrides {current_window}
3024+
{winid}? (`integer`) Open the tree in the specified
3025+
|window-ID|, overrides {current_window}
30243026
• {find_file}? (`boolean`, default: false) Find the current
30253027
buffer.
30263028
{focus}? (`boolean`, default: true) Focus the tree when
@@ -3055,14 +3057,14 @@ toggle_no_buffer_filter()
30553057
Toggle |nvim_tree.Config.Filters| {no_buffer} filter.
30563058

30573059
winid({opts}) *nvim_tree.api.tree.winid()*
3058-
Retrieve the winid of the open tree.
3060+
Retrieve the window of the open tree.
30593061

30603062
Parameters: ~
30613063
{opts} (`table?`) optional
30623064
{tabpage}? (`integer`) |tab-ID| 0 or nil for current.
30633065

30643066
Return: ~
3065-
(`integer?`) |winid|, nil if tree is not visible.
3067+
(`integer?`) |window-ID|, nil if tree is not visible.
30663068

30673069

30683070
vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:

lua/nvim-tree/api.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,15 @@ Api.marks.navigate.next = wrap_explorer_member("marks", "navigate_next")
364364
Api.marks.navigate.prev = wrap_explorer_member("marks", "navigate_prev")
365365
Api.marks.navigate.select = wrap_explorer_member("marks", "navigate_select")
366366

367+
function Api.hydrate_config(tree)
368+
Api.tree = tree
369+
367370
Api.config.mappings.get_keymap = wrap(keymap.get_keymap)
368371
Api.config.mappings.get_keymap_default = wrap(keymap.get_keymap_default)
369372
Api.config.mappings.default_on_attach = keymap.default_on_attach
370373

374+
end
375+
371376
Api.diagnostics.hi_test = wrap(appearance_hi_test)
372377

373378
Api.commands.get = wrap(function()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---@meta
2+
3+
4+
-- # TODO #3088 this should be api/config.lua however that results in a filename clash in gen_vimdoc_config.lua
5+
6+
7+
local nvim_tree = { api = { config = { mappings = {} } } }
8+
9+
10+
11+
---Retrieve all buffer local mappings for nvim-tree. These are the mappings that are applied by [nvim_tree.Config] {on_attach}, which may include default mappings.
12+
---
13+
---@return vim.api.keyset.get_keymap[]
14+
function nvim_tree.api.config.mappings.get_keymap() end
15+
16+
17+
18+
--- Retrieves the buffer local mappings for nvim-tree that are applied by [nvim_tree.api.config.mappings.default_on_attach()]
19+
---
20+
---@return vim.api.keyset.get_keymap[]
21+
function nvim_tree.api.config.mappings.get_keymap_default() end
22+
23+
24+
25+
---Apply all [nvim-tree-mappings-default]. Call from your [nvim_tree.Config] {on_attach}.
26+
---
27+
---@param bufnr integer use the `bufnr` passed to {on_attach}
28+
function nvim_tree.api.config.mappings.default_on_attach(bufnr) end
29+
30+
31+
32+
require("nvim-tree.api").hydrate_config(nvim_tree.api.config)
33+
34+
return nvim_tree.api.tree

lua/nvim-tree/api/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
return {
2-
tree = require("nvim-tree.api.tree")
2+
config = require("nvim-tree.api.config.mappings"),
3+
tree = require("nvim-tree.api.tree"),
34
}

lua/nvim-tree/api/tree.lua

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ local nvim_tree = { api = { tree = {} } }
1313
---(default: false)
1414
---@field current_window? boolean
1515
---
16-
---Open the tree in the specified [winid], overrides {current_window}
17-
---@field winid? number
16+
---Open the tree in the specified [window-ID], overrides {current_window}
17+
---@field winid? integer
1818
---
1919
---Find the current buffer.
2020
---(default: false)
@@ -41,8 +41,8 @@ function nvim_tree.api.tree.open(opts) end
4141
---(default: false)
4242
---@field current_window? boolean
4343
---
44-
---Open the tree in the specified [winid], overrides {current_window}
45-
---@field winid? number
44+
---Open the tree in the specified [window-ID], overrides {current_window}
45+
---@field winid? integer
4646
---
4747
---Find the current buffer.
4848
---(default: false)
@@ -93,10 +93,10 @@ function nvim_tree.api.tree.reload() end
9393
---@field width nvim_tree.Config.View.WidthSpec|nvim_tree.Config.View.Width
9494
---
9595
---Set the width.
96-
---@field absolute number
96+
---@field absolute integer
9797
---
9898
---Increase or decrease the width.
99-
---@field relative number
99+
---@field relative integer
100100

101101
---Resize the tree, persisting the new size. Resets to [nvim_tree.Config.View] {width} when no {opts} provided.
102102
---
@@ -143,8 +143,8 @@ function nvim_tree.api.tree.get_nodes() end
143143
---@class nvim_tree.api.tree.find_file.Opts
144144
---@inlinedoc
145145
---
146-
---Absolute/relative path OR [bufnr()] to find.
147-
---@field buf? string|number
146+
---Absolute/relative path OR `bufnr` to find.
147+
---@field buf? string|integer
148148
---
149149
---Open the tree if necessary.
150150
---(default: false)
@@ -154,8 +154,8 @@ function nvim_tree.api.tree.get_nodes() end
154154
---(default: false)
155155
---@field current_window? boolean
156156
---
157-
---Open the tree in the specified [winid], overrides {current_window}
158-
---@field winid? number
157+
---Open the tree in the specified [window-ID], overrides {current_window}
158+
---@field winid? integer
159159
---
160160
---Update root after find, see [nvim_tree.Config.UpdateFocusedFile] {update_root}
161161
---(default: false)
@@ -250,7 +250,8 @@ function nvim_tree.api.tree.toggle_help() end
250250

251251
---Checks if a buffer is an nvim-tree.
252252
---
253-
---@param bufnr? number 0 or nil for current buffer.
253+
---@param bufnr? integer 0 or nil for current buffer.
254+
---
254255
---@return boolean
255256
function nvim_tree.api.tree.is_tree_buf(bufnr) end
256257

@@ -280,10 +281,10 @@ function nvim_tree.api.tree.is_visible(opts) end
280281
---[tab-ID] 0 or nil for current.
281282
---@field tabpage? integer
282283

283-
---Retrieve the winid of the open tree.
284+
---Retrieve the window of the open tree.
284285
---
285286
---@param opts? nvim_tree.api.tree.winid.Opts optional
286-
---@return integer? [winid], nil if tree is not visible.
287+
---@return integer? [window-ID], nil if tree is not visible.
287288
function nvim_tree.api.tree.winid(opts) end
288289

289290

scripts/gen_vimdoc_config.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ local modules = {
3131
{ helptag = "nvim-tree-config-experimental", title = "Class: Config.Experimental", path = "./lua/nvim_tree/_meta/config/experimental.lua", },
3232
{ helptag = "nvim-tree-config-log", title = "Class: Config.Log", path = "./lua/nvim_tree/_meta/config/log.lua", },
3333

34+
{ helptag = "nvim-tree-api-config", title = "Lua module: nvim_tree.api.config", path = "./lua/nvim_tree/api/config/mappings.lua", },
3435
{ helptag = "nvim-tree-api-tree", title = "Lua module: nvim_tree.api.tree", path = "./lua/nvim_tree/api/tree.lua", },
3536
}
3637

@@ -39,13 +40,13 @@ for _, m in ipairs(modules) do
3940
m.file = vim.fn.fnamemodify(m.path, ":t")
4041
end
4142

42-
--module name is derived by the generator as the file name with the first letter capitalised
43+
--section name is derived by the generator as the file name with the first letter capitalised
4344
--except for some like UI
4445
---@type table<string, Module>
45-
local modules_by_name = {}
46+
local modules_by_section = {}
4647
for _, m in ipairs(modules) do
4748
local name = m.name or m.file:gsub(".lua", ""):gsub("^%l", string.upper)
48-
modules_by_name[name] = m
49+
modules_by_section[name] = m
4950
end
5051

5152
---@diagnostic disable-next-line: undefined-doc-name
@@ -62,17 +63,17 @@ local config = {
6263

6364
section_fmt = function(name)
6465
print(string.format("section_fmt name=%s", name))
65-
return modules_by_name[name] and modules_by_name[name].title or error(string.format("unknown module %s passed to section_fmt", name))
66+
return modules_by_section[name] and modules_by_section[name].title or error(string.format("unknown module %s passed to section_fmt", name))
6667
end,
6768

6869
helptag_fmt = function(name)
6970
print(string.format("helptag_fmt name=%s", name))
70-
return modules_by_name[name] and modules_by_name[name].helptag or error(string.format("unknown module %s passed to helptag_fmt", name))
71+
return modules_by_section[name] and modules_by_section[name].helptag or error(string.format("unknown module %s passed to helptag_fmt", name))
7172
end,
7273

7374
-- optional, no default xform
7475
fn_xform = function(fun)
75-
print(string.format("fn_xform fun=%s", vim.inspect(fun)))
76+
-- print(string.format("fn_xform fun=%s", vim.inspect(fun)))
7677

7778
if (fun.module) then
7879
-- generator doesn't strip meta

scripts/help-update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_ON_ATTACH.help
4949
}; /${end}/p; d; }" doc/nvim-tree-lua.txt
5050

5151
# TODO #3088 remove once all api references have been updated
52-
sed -i -e "s/nvim-tree-api.tree/nvim_tree.api.tree/g" doc/nvim-tree-lua.txt
52+
sed -i -e "s/nvim\-tree\-api\.tree\./nvim_tree.api.tree./g" doc/nvim-tree-lua.txt

scripts/lintdoc.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env sh
22

3-
43
# Wrapper around Nvim help linter lintdoc.lua, run as part of Nvim's make lintdoc target.
54
#
65
# Requires Nvim to have been built.

0 commit comments

Comments
 (0)