docs: generate params/returns in builtin.txt #30654

This commit is contained in:
Justin M. Keyes 2024-10-07 05:32:49 -07:00 committed by GitHub
parent 2377443cd2
commit 7335988ce6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 3643 additions and 609 deletions

2948
runtime/doc/builtin.txt generated

File diff suppressed because it is too large Load Diff

View File

@ -173,6 +173,7 @@ FUNCTIONS
- *jobclose()* Obsolete name for |chanclose()| - *jobclose()* Obsolete name for |chanclose()|
- *jobsend()* Obsolete name for |chansend()| - *jobsend()* Obsolete name for |chansend()|
- *last_buffer_nr()* Obsolete name for bufnr("$"). - *last_buffer_nr()* Obsolete name for bufnr("$").
- *rpcstart()* Use |jobstart()| with `{'rpc': v:true}` instead.
- *rpcstop()* Use |jobstop()| instead to stop any job, or - *rpcstop()* Use |jobstop()| instead to stop any job, or
`chanclose(id, "rpc")` to close RPC communication `chanclose(id, "rpc")` to close RPC communication
without stopping the job. Use chanclose(id) to close without stopping the job. Use chanclose(id) to close

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,11 @@
-- Generator for various vimdoc and Lua type files -- Generator for various vimdoc and Lua type files
local util = require('scripts.util')
local fmt = string.format
local DEP_API_METADATA = 'build/funcs_metadata.mpack' local DEP_API_METADATA = 'build/funcs_metadata.mpack'
local TEXT_WIDTH = 78
--- @class vim.api.metadata --- @class vim.api.metadata
--- @field name string --- @field name string
@ -170,9 +174,9 @@ local function render_fun_sig(f, params)
end end
if LUA_KEYWORDS[f] then if LUA_KEYWORDS[f] then
return string.format("vim.fn['%s'] = function(%s) end", f, param_str) return fmt("vim.fn['%s'] = function(%s) end", f, param_str)
else else
return string.format('function vim.fn.%s(%s) end', f, param_str) return fmt('function vim.fn.%s(%s) end', f, param_str)
end end
end end
@ -306,14 +310,13 @@ local function norm_text(x, special)
) )
end end
--- Generates LuaLS docstring for an API function.
--- @param _f string --- @param _f string
--- @param fun vim.EvalFn --- @param fun vim.EvalFn
--- @param write fun(line: string) --- @param write fun(line: string)
local function render_api_meta(_f, fun, write) local function render_api_meta(_f, fun, write)
write('') write('')
local util = require('scripts.util')
if vim.startswith(fun.name, 'nvim__') then if vim.startswith(fun.name, 'nvim__') then
write('--- @private') write('--- @private')
end end
@ -365,7 +368,7 @@ local function render_api_meta(_f, fun, write)
end end
local param_str = table.concat(param_names, ', ') local param_str = table.concat(param_names, ', ')
write(string.format('function vim.api.%s(%s) end', fun.name, param_str)) write(fmt('function vim.api.%s(%s) end', fun.name, param_str))
end end
--- @return table<string, vim.EvalFn> --- @return table<string, vim.EvalFn>
@ -393,6 +396,7 @@ local function get_api_keysets_meta()
return ret return ret
end end
--- Generates LuaLS docstring for an API keyset.
--- @param _f string --- @param _f string
--- @param fun vim.EvalFn --- @param fun vim.EvalFn
--- @param write fun(line: string) --- @param write fun(line: string)
@ -412,6 +416,7 @@ local function get_eval_meta()
return require('src/nvim/eval').funcs return require('src/nvim/eval').funcs
end end
--- Generates LuaLS docstring for a Vimscript "eval" function.
--- @param f string --- @param f string
--- @param fun vim.EvalFn --- @param fun vim.EvalFn
--- @param write fun(line: string) --- @param write fun(line: string)
@ -421,7 +426,6 @@ local function render_eval_meta(f, fun, write)
end end
local funname = fun.name or f local funname = fun.name or f
local params = process_params(fun.params) local params = process_params(fun.params)
write('') write('')
@ -445,16 +449,18 @@ local function render_eval_meta(f, fun, write)
for i, param in ipairs(params) do for i, param in ipairs(params) do
local pname, ptype = param[1], param[2] local pname, ptype = param[1], param[2]
local optional = (pname ~= '...' and i > req_args) and '?' or '' local optional = (pname ~= '...' and i > req_args) and '?' or ''
write(string.format('--- @param %s%s %s', pname, optional, ptype)) write(fmt('--- @param %s%s %s', pname, optional, ptype))
end end
if fun.returns ~= false then if fun.returns ~= false then
write('--- @return ' .. (fun.returns or 'any')) local ret_desc = fun.returns_desc and ' # ' .. fun.returns_desc or ''
write('--- @return ' .. (fun.returns or 'any') .. ret_desc)
end end
write(render_fun_sig(funname, params)) write(render_fun_sig(funname, params))
end end
--- Generates vimdoc heading for a Vimscript "eval" function signature.
--- @param name string --- @param name string
--- @param name_tag boolean --- @param name_tag boolean
--- @param fun vim.EvalFn --- @param fun vim.EvalFn
@ -486,19 +492,16 @@ local function render_sig_and_tag(name, name_tag, fun, write)
write(string.rep(' ', tag_pad_len) .. tag) write(string.rep(' ', tag_pad_len) .. tag)
write(fun.signature) write(fun.signature)
else else
write(string.format('%s%s%s', fun.signature, string.rep(' ', tag_pad_len - siglen), tag)) write(fmt('%s%s%s', fun.signature, string.rep(' ', tag_pad_len - siglen), tag))
end end
end end
--- Generates vimdoc for a Vimscript "eval" function.
--- @param f string --- @param f string
--- @param fun vim.EvalFn --- @param fun vim.EvalFn
--- @param write fun(line: string) --- @param write fun(line: string)
local function render_eval_doc(f, fun, write) local function render_eval_doc(f, fun, write)
if fun.deprecated then if fun.deprecated or not fun.signature then
return
end
if not fun.signature then
return return
end end
@ -508,6 +511,9 @@ local function render_eval_doc(f, fun, write)
return return
end end
local params = process_params(fun.params)
local req_args = type(fun.args) == 'table' and fun.args[1] or fun.args or 0
local desc_l = split(vim.trim(fun.desc)) local desc_l = split(vim.trim(fun.desc))
for _, l in ipairs(desc_l) do for _, l in ipairs(desc_l) do
l = l:gsub('^ ', '') l = l:gsub('^ ', '')
@ -523,6 +529,26 @@ local function render_eval_doc(f, fun, write)
if #desc_l > 0 and not desc_l[#desc_l]:match('^<?$') then if #desc_l > 0 and not desc_l[#desc_l]:match('^<?$') then
write('') write('')
end end
if #params > 0 then
write(util.md_to_vimdoc('Parameters: ~', 16, 16, TEXT_WIDTH))
for i, param in ipairs(params) do
local pname, ptype = param[1], param[2]
local optional = (pname ~= '...' and i > req_args) and '?' or ''
local s = fmt('- %-14s (`%s%s`)', fmt('{%s}', pname), ptype, optional)
write(util.md_to_vimdoc(s, 16, 18, TEXT_WIDTH))
end
write('')
end
if fun.returns ~= false then
write(util.md_to_vimdoc('Return: ~', 16, 16, TEXT_WIDTH))
local ret = ('(`%s`)'):format((fun.returns or 'any'))
ret = ret .. (fun.returns_desc and ' ' .. fun.returns_desc or '')
ret = util.md_to_vimdoc(ret, 18, 18, TEXT_WIDTH)
write(ret)
write('')
end
end end
--- @param d vim.option_defaults --- @param d vim.option_defaults
@ -760,9 +786,9 @@ local function render_option_doc(_f, opt, write)
local name_str --- @type string local name_str --- @type string
if opt.abbreviation then if opt.abbreviation then
name_str = string.format("'%s' '%s'", opt.full_name, opt.abbreviation) name_str = fmt("'%s' '%s'", opt.full_name, opt.abbreviation)
else else
name_str = string.format("'%s'", opt.full_name) name_str = fmt("'%s'", opt.full_name)
end end
local otype = opt.type == 'boolean' and 'boolean' or opt.type local otype = opt.type == 'boolean' and 'boolean' or opt.type
@ -770,13 +796,13 @@ local function render_option_doc(_f, opt, write)
local v = render_option_default(opt.defaults, true) local v = render_option_default(opt.defaults, true)
local pad = string.rep('\t', math.max(1, math.ceil((24 - #name_str) / 8))) local pad = string.rep('\t', math.max(1, math.ceil((24 - #name_str) / 8)))
if opt.defaults.doc then if opt.defaults.doc then
local deflen = #string.format('%s%s%s (', name_str, pad, otype) local deflen = #fmt('%s%s%s (', name_str, pad, otype)
--- @type string --- @type string
v = v:gsub('\n', '\n' .. string.rep(' ', deflen - 2)) v = v:gsub('\n', '\n' .. string.rep(' ', deflen - 2))
end end
write(string.format('%s%s%s\t(default %s)', name_str, pad, otype, v)) write(fmt('%s%s%s\t(default %s)', name_str, pad, otype, v))
else else
write(string.format('%s\t%s', name_str, otype)) write(fmt('%s\t%s', name_str, otype))
end end
write('\t\t\t' .. scope_to_doc(opt.scope) .. scope_more_doc(opt)) write('\t\t\t' .. scope_to_doc(opt.scope) .. scope_more_doc(opt))

File diff suppressed because it is too large Load Diff