doc: better type annotations for API methods

This commit is contained in:
Steven Arcangeli 2024-05-21 19:39:37 -07:00
parent 06a19f77f1
commit 259b1fbc84
4 changed files with 21 additions and 15 deletions

View file

@ -136,7 +136,7 @@ Select the entry under the cursor
| Param | Type | Desc | | | Param | Type | Desc | |
| -------- | ---------------------------- | -------------------------------------------------- | ---------------------------------------------------- | | -------- | ---------------------------- | -------------------------------------------------- | ---------------------------------------------------- |
| opts | `nil\|table` | | | | opts | `nil\|oil.SelectOpts` | | |
| | vertical | `boolean` | Open the buffer in a vertical split | | | vertical | `boolean` | Open the buffer in a vertical split |
| | horizontal | `boolean` | Open the buffer in a horizontal split | | | horizontal | `boolean` | Open the buffer in a horizontal split |
| | split | `"aboveleft"\|"belowright"\|"topleft"\|"botright"` | Split modifier | | | split | `"aboveleft"\|"belowright"\|"topleft"\|"botright"` | Split modifier |

View file

@ -311,7 +311,7 @@ select({opts}, {callback}) *oil.selec
Select the entry under the cursor Select the entry under the cursor
Parameters: Parameters:
{opts} `nil|table` {opts} `nil|oil.SelectOpts`
{vertical} `boolean` Open the buffer in a vertical split {vertical} `boolean` Open the buffer in a vertical split
{horizontal} `boolean` Open the buffer in a horizontal split {horizontal} `boolean` Open the buffer in a horizontal split
{split} `"aboveleft"|"belowright"|"topleft"|"botright"` Split {split} `"aboveleft"|"belowright"|"topleft"|"botright"` Split

View file

@ -539,13 +539,15 @@ M.open_preview = function(opts, callback)
end) end)
end end
---@class (exact) oil.SelectOpts
---@field vertical boolean Open the buffer in a vertical split
---@field horizontal boolean Open the buffer in a horizontal split
---@field split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
---@field tab boolean Open the buffer in a new tab
---@field close boolean Close the original oil buffer once selection is made
---Select the entry under the cursor ---Select the entry under the cursor
---@param opts nil|table ---@param opts nil|oil.SelectOpts
--- vertical boolean Open the buffer in a vertical split
--- horizontal boolean Open the buffer in a horizontal split
--- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
--- tab boolean Open the buffer in a new tab
--- close boolean Close the original oil buffer once selection is made
---@param callback nil|fun(err: nil|string) Called once all entries have been opened ---@param callback nil|fun(err: nil|string) Called once all entries have been opened
M.select = function(opts, callback) M.select = function(opts, callback)
local cache = require("oil.cache") local cache = require("oil.cache")

View file

@ -6,16 +6,18 @@ from typing import List
from nvim_doc_tools import ( from nvim_doc_tools import (
LuaParam, LuaParam,
LuaTypes,
Vimdoc, Vimdoc,
VimdocSection, VimdocSection,
generate_md_toc, generate_md_toc,
indent, indent,
leftright, leftright,
parse_directory,
parse_functions, parse_functions,
read_nvim_json, read_nvim_json,
read_section, read_section,
render_md_api, render_md_api2,
render_vimdoc_api, render_vimdoc_api2,
replace_section, replace_section,
wrap, wrap,
) )
@ -37,8 +39,9 @@ def add_md_link_path(path: str, lines: List[str]) -> List[str]:
def update_md_api(): def update_md_api():
api_doc = os.path.join(DOC, "api.md") api_doc = os.path.join(DOC, "api.md")
funcs = parse_functions(os.path.join(ROOT, "lua", "oil", "init.lua")) types = parse_directory(os.path.join(ROOT, "lua"))
lines = ["\n"] + render_md_api(funcs, 2) + ["\n"] funcs = types.files["oil/init.lua"].functions
lines = ["\n"] + render_md_api2(funcs, types, 2) + ["\n"]
replace_section( replace_section(
api_doc, api_doc,
r"^<!-- API -->$", r"^<!-- API -->$",
@ -264,7 +267,7 @@ def get_columns_vimdoc() -> "VimdocSection":
section.body.extend(wrap(col.summary, 4)) section.body.extend(wrap(col.summary, 4))
section.body.append("\n") section.body.append("\n")
section.body.append(" Parameters:\n") section.body.append(" Parameters:\n")
section.body.extend(format_vimdoc_params(col.params, 6)) section.body.extend(format_vimdoc_params(col.params, LuaTypes(), 6))
section.body.append("\n") section.body.append("\n")
return section return section
@ -302,12 +305,13 @@ Windows:
def generate_vimdoc(): def generate_vimdoc():
doc = Vimdoc("oil.txt", "oil") doc = Vimdoc("oil.txt", "oil")
funcs = parse_functions(os.path.join(ROOT, "lua", "oil", "init.lua")) types = parse_directory(os.path.join(ROOT, "lua"))
funcs = types.files["oil/init.lua"].functions
doc.sections.extend( doc.sections.extend(
[ [
get_options_vimdoc(), get_options_vimdoc(),
get_options_detail_vimdoc(), get_options_detail_vimdoc(),
VimdocSection("API", "oil-api", render_vimdoc_api("oil", funcs)), VimdocSection("API", "oil-api", render_vimdoc_api2("oil", funcs, types)),
get_columns_vimdoc(), get_columns_vimdoc(),
get_actions_vimdoc(), get_actions_vimdoc(),
get_highlights_vimdoc(), get_highlights_vimdoc(),