Skip to content

Commit f994f61

Browse files
committed
doc(#2934): POC to use gen_vimdoc.lua for decorator meta
1 parent b8b44b6 commit f994f61

5 files changed

Lines changed: 973 additions & 13 deletions

File tree

doc/decorator.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
*decorator.txt* nvim-tree decorators
2+
3+
==============================================================================
4+
==============================================================================
5+
Lua module: nvim_tree.api.decorator *nvim-tree-decorators*
6+
7+
*nvim_tree.api.decorator.UserDecorator*
8+
Custom decorator, see :help nvim-tree-decorators
9+
10+
Fields: ~
11+
{enabled} (`boolean`)
12+
• {highlight_range} (`nvim_tree.api.decorator.HighlightRange`)
13+
• {icon_placement} (`nvim_tree.api.decorator.IconPlacement`)
14+
{extend} (`fun(self: nvim_tree.api.decorator.UserDecorator)`)
15+
See |UserDecorator:extend()|.
16+
{new} (`fun(self: nvim_tree.api.decorator.UserDecorator)`)
17+
See |UserDecorator:new()|.
18+
• {icon_node} (`fun(self: nvim_tree.api.decorator.UserDecorator, node: nvim_tree.api.Node): nvim_tree.api.HighlightedString?`)
19+
See |UserDecorator:icon_node()|.
20+
{icons} (`fun(self: nvim_tree.api.decorator.UserDecorator, node: nvim_tree.api.Node): nvim_tree.api.HighlightedString[]?`)
21+
See |UserDecorator:icons()|.
22+
• {highlight_group} (`fun(self: nvim_tree.api.decorator.UserDecorator, node: nvim_tree.api.Node): string?`)
23+
See |UserDecorator:highlight_group()|.
24+
25+
26+
UserDecorator:extend() *nvim_tree.api.decorator.UserDecorator:extend()*
27+
Create your decorator class
28+
29+
*nvim_tree.api.decorator.UserDecorator:highlight_group()*
30+
UserDecorator:highlight_group({node})
31+
Abstract: optionally implement to provide one highlight group to apply to
32+
your highlight_range.
33+
34+
Parameters: ~
35+
{node} (`nvim_tree.api.Node`)
36+
37+
Return: ~
38+
(`string?`) highlight_group
39+
40+
*nvim_tree.api.decorator.UserDecorator:icon_node()*
41+
UserDecorator:icon_node({node})
42+
Abstract: optionally implement to set the node's icon
43+
44+
Parameters: ~
45+
{node} (`nvim_tree.api.Node`)
46+
47+
Return: ~
48+
(`nvim_tree.api.HighlightedString?`) icon_node
49+
50+
*nvim_tree.api.decorator.UserDecorator:icons()*
51+
UserDecorator:icons({node})
52+
Abstract: optionally implement to provide icons and the highlight groups
53+
for your icon_placement.
54+
55+
Parameters: ~
56+
{node} (`nvim_tree.api.Node`)
57+
58+
Return: ~
59+
(`nvim_tree.api.HighlightedString[]?`) icons
60+
61+
UserDecorator:new() *nvim_tree.api.decorator.UserDecorator:new()*
62+
Abstract: no-args constructor must be implemented and will be called once
63+
per tree render. Must set all fields.
64+
65+
66+
vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---@meta
22
error("Cannot require a meta file")
33

4-
local nvim_tree = { api = { decorator = {} } }
5-
64
---Highlight group range as per nvim-tree.renderer.highlight_*
75
---@alias nvim_tree.api.decorator.HighlightRange "none" | "icon" | "name" | "all"
86

@@ -14,41 +12,41 @@ local nvim_tree = { api = { decorator = {} } }
1412

1513
---Custom decorator, see :help nvim-tree-decorators
1614
---
17-
---@class (exact) nvim_tree.api.decorator.UserDecorator
18-
---@field protected enabled boolean
19-
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
20-
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
21-
nvim_tree.api.decorator.UserDecorator = {}
15+
---@class nvim_tree.api.decorator.UserDecorator
16+
---@field enabled boolean
17+
---@field highlight_range nvim_tree.api.decorator.HighlightRange
18+
---@field icon_placement nvim_tree.api.decorator.IconPlacement
19+
local UserDecorator = {}
2220

2321
---Create your decorator class
2422
---
25-
function nvim_tree.api.decorator.UserDecorator:extend() end
23+
function UserDecorator:extend() end
2624

2725
---Abstract: no-args constructor must be implemented and will be called once per tree render.
2826
---Must set all fields.
2927
---
30-
function nvim_tree.api.decorator.UserDecorator:new() end
28+
function UserDecorator:new() end
3129

3230
---Abstract: optionally implement to set the node's icon
3331
---
3432
---@param node nvim_tree.api.Node
3533
---@return nvim_tree.api.HighlightedString? icon_node
36-
function nvim_tree.api.decorator.UserDecorator:icon_node(node) end
34+
function UserDecorator:icon_node(node) end
3735

3836
---Abstract: optionally implement to provide icons and the highlight groups for your icon_placement.
3937
---
4038
---@param node nvim_tree.api.Node
4139
---@return nvim_tree.api.HighlightedString[]? icons
42-
function nvim_tree.api.decorator.UserDecorator:icons(node) end
40+
function UserDecorator:icons(node) end
4341

4442
---Abstract: optionally implement to provide one highlight group to apply to your highlight_range.
4543
---
4644
---@param node nvim_tree.api.Node
4745
---@return string? highlight_group
48-
function nvim_tree.api.decorator.UserDecorator:highlight_group(node) end
46+
function UserDecorator:highlight_group(node) end
4947

5048
---Define a sign. This should be called in the constructor.
5149
---
5250
---@protected
5351
---@param icon nvim_tree.api.HighlightedString?
54-
function nvim_tree.api.decorator.UserDecorator:define_sign(icon) end
52+
function UserDecorator:define_sign(icon) end

scripts/doc.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
if [ ! -d "${NEOVIM_SRC}" ]; then
6+
echo "\$NEOVIM_SRC not set"
7+
exit 1
8+
fi
9+
10+
# runtime/doc is hardcoded, copy it in
11+
mkdir -p runtime/doc
12+
cp "doc/decorator.txt" runtime/doc
13+
14+
# use luacacts etc. from neovim src
15+
LUA_PATH="${NEOVIM_SRC}/src/?.lua"
16+
17+
# generate
18+
scripts/gen_vimdoc.lua
19+
20+
# move the output
21+
mv "runtime/doc/decorator.txt" doc
22+
rmdir runtime/doc
23+
rmdir runtime
24+

scripts/gen_vimdoc.decorator.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---@diagnostic disable: undefined-doc-name
2+
3+
--- @param fun nvim.luacats.parser.fun
4+
--- @return string
5+
local function fn_helptag_fmt_common0(fun)
6+
local fn_sfx = fun.table and '' or '()'
7+
if fun.classvar then
8+
return string.format('%s:%s%s', fun.classvar, fun.name, fn_sfx)
9+
end
10+
if fun.module then
11+
return string.format('%s.%s%s', fun.module, fun.name, fn_sfx)
12+
end
13+
return fun.name .. fn_sfx
14+
end
15+
16+
return {
17+
filename = "decorator.txt",
18+
section_order = {
19+
"api_decorator.lua",
20+
},
21+
files = {
22+
-- module is derived soley from the file name, first letter capitalised
23+
-- 'runtime/lua/nvim-tree/foo/api_decorator.lua',
24+
"/home/alex/src/nvim-tree/master/lua/nvim-tree/_meta/api_decorator.lua"
25+
},
26+
section_fmt = function(name)
27+
if name == "Api_decorator" then
28+
return "Lua module: nvim_tree.api.decorator"
29+
end
30+
error(string.format("unknown module %s passed to section_fmt", name))
31+
end,
32+
helptag_fmt = function(name)
33+
-- used to locate the help section
34+
if name == "Api_decorator" then
35+
return "nvim-tree-decorators"
36+
end
37+
error(string.format("unknown module %s passed to helptag_fmt", name))
38+
end,
39+
fn_helptag_fmt = function(fun)
40+
-- use the fully qualified class name in the tag for methods
41+
-- this is done everywhere but for classes
42+
local common = fn_helptag_fmt_common0(fun)
43+
local helptag = common
44+
if fun.class then
45+
helptag = common:gsub(fun.classvar, fun.class)
46+
end
47+
return helptag
48+
end,
49+
}

0 commit comments

Comments
 (0)