Skip to content

Commit 259b1fb

Browse files
committed
doc: better type annotations for API methods
1 parent 06a19f7 commit 259b1fb

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

doc/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Select the entry under the cursor
136136

137137
| Param | Type | Desc | |
138138
| -------- | ---------------------------- | -------------------------------------------------- | ---------------------------------------------------- |
139-
| opts | `nil\|table` | | |
139+
| opts | `nil\|oil.SelectOpts` | | |
140140
| | vertical | `boolean` | Open the buffer in a vertical split |
141141
| | horizontal | `boolean` | Open the buffer in a horizontal split |
142142
| | split | `"aboveleft"\|"belowright"\|"topleft"\|"botright"` | Split modifier |

doc/oil.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ select({opts}, {callback}) *oil.selec
311311
Select the entry under the cursor
312312

313313
Parameters:
314-
{opts} `nil|table`
314+
{opts} `nil|oil.SelectOpts`
315315
{vertical} `boolean` Open the buffer in a vertical split
316316
{horizontal} `boolean` Open the buffer in a horizontal split
317317
{split} `"aboveleft"|"belowright"|"topleft"|"botright"` Split

lua/oil/init.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,15 @@ M.open_preview = function(opts, callback)
539539
end)
540540
end
541541

542+
---@class (exact) oil.SelectOpts
543+
---@field vertical boolean Open the buffer in a vertical split
544+
---@field horizontal boolean Open the buffer in a horizontal split
545+
---@field split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
546+
---@field tab boolean Open the buffer in a new tab
547+
---@field close boolean Close the original oil buffer once selection is made
548+
542549
---Select the entry under the cursor
543-
---@param opts nil|table
544-
--- vertical boolean Open the buffer in a vertical split
545-
--- horizontal boolean Open the buffer in a horizontal split
546-
--- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
547-
--- tab boolean Open the buffer in a new tab
548-
--- close boolean Close the original oil buffer once selection is made
550+
---@param opts nil|oil.SelectOpts
549551
---@param callback nil|fun(err: nil|string) Called once all entries have been opened
550552
M.select = function(opts, callback)
551553
local cache = require("oil.cache")

scripts/generate.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
from nvim_doc_tools import (
88
LuaParam,
9+
LuaTypes,
910
Vimdoc,
1011
VimdocSection,
1112
generate_md_toc,
1213
indent,
1314
leftright,
15+
parse_directory,
1416
parse_functions,
1517
read_nvim_json,
1618
read_section,
17-
render_md_api,
18-
render_vimdoc_api,
19+
render_md_api2,
20+
render_vimdoc_api2,
1921
replace_section,
2022
wrap,
2123
)
@@ -37,8 +39,9 @@ def add_md_link_path(path: str, lines: List[str]) -> List[str]:
3739

3840
def update_md_api():
3941
api_doc = os.path.join(DOC, "api.md")
40-
funcs = parse_functions(os.path.join(ROOT, "lua", "oil", "init.lua"))
41-
lines = ["\n"] + render_md_api(funcs, 2) + ["\n"]
42+
types = parse_directory(os.path.join(ROOT, "lua"))
43+
funcs = types.files["oil/init.lua"].functions
44+
lines = ["\n"] + render_md_api2(funcs, types, 2) + ["\n"]
4245
replace_section(
4346
api_doc,
4447
r"^<!-- API -->$",
@@ -264,7 +267,7 @@ def get_columns_vimdoc() -> "VimdocSection":
264267
section.body.extend(wrap(col.summary, 4))
265268
section.body.append("\n")
266269
section.body.append(" Parameters:\n")
267-
section.body.extend(format_vimdoc_params(col.params, 6))
270+
section.body.extend(format_vimdoc_params(col.params, LuaTypes(), 6))
268271
section.body.append("\n")
269272
return section
270273

@@ -302,12 +305,13 @@ def get_trash_vimdoc() -> "VimdocSection":
302305

303306
def generate_vimdoc():
304307
doc = Vimdoc("oil.txt", "oil")
305-
funcs = parse_functions(os.path.join(ROOT, "lua", "oil", "init.lua"))
308+
types = parse_directory(os.path.join(ROOT, "lua"))
309+
funcs = types.files["oil/init.lua"].functions
306310
doc.sections.extend(
307311
[
308312
get_options_vimdoc(),
309313
get_options_detail_vimdoc(),
310-
VimdocSection("API", "oil-api", render_vimdoc_api("oil", funcs)),
314+
VimdocSection("API", "oil-api", render_vimdoc_api2("oil", funcs, types)),
311315
get_columns_vimdoc(),
312316
get_actions_vimdoc(),
313317
get_highlights_vimdoc(),

0 commit comments

Comments
 (0)