mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
docs: do not escape Lua keywords #31467
This commit is contained in:
parent
ba7370a902
commit
2550b5e9bd
18
runtime/doc/builtin.txt
generated
18
runtime/doc/builtin.txt
generated
@ -2997,7 +2997,7 @@ getbufline({buf}, {lnum} [, {end}]) *getbufline()*
|
||||
Parameters: ~
|
||||
• {buf} (`integer|string`)
|
||||
• {lnum} (`integer`)
|
||||
• {end_} (`integer?`)
|
||||
• {end} (`integer?`)
|
||||
|
||||
Return: ~
|
||||
(`any`)
|
||||
@ -3635,7 +3635,7 @@ getline({lnum} [, {end}]) *getline()*
|
||||
|
||||
Parameters: ~
|
||||
• {lnum} (`integer|string`)
|
||||
• {end_} (`nil|false?`)
|
||||
• {end} (`nil|false?`)
|
||||
|
||||
Return: ~
|
||||
(`string`)
|
||||
@ -6292,7 +6292,7 @@ matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}]) *matchbufline()*
|
||||
• {buf} (`string|integer`)
|
||||
• {pat} (`string`)
|
||||
• {lnum} (`string|integer`)
|
||||
• {end_} (`string|integer`)
|
||||
• {end} (`string|integer`)
|
||||
• {dict} (`table?`)
|
||||
|
||||
Return: ~
|
||||
@ -7786,7 +7786,7 @@ reltime({start}, {end})
|
||||
|
||||
Parameters: ~
|
||||
• {start} (`any?`)
|
||||
• {end_} (`any?`)
|
||||
• {end} (`any?`)
|
||||
|
||||
Return: ~
|
||||
(`any`)
|
||||
@ -7847,7 +7847,7 @@ remove({list}, {idx}, {end})
|
||||
Parameters: ~
|
||||
• {list} (`any[]`)
|
||||
• {idx} (`integer`)
|
||||
• {end_} (`integer?`)
|
||||
• {end} (`integer?`)
|
||||
|
||||
Return: ~
|
||||
(`any`)
|
||||
@ -7869,7 +7869,7 @@ remove({blob}, {idx}, {end})
|
||||
Parameters: ~
|
||||
• {blob} (`any`)
|
||||
• {idx} (`integer`)
|
||||
• {end_} (`integer?`)
|
||||
• {end} (`integer?`)
|
||||
|
||||
Return: ~
|
||||
(`any`)
|
||||
@ -8500,7 +8500,7 @@ searchpair({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline} [, {timeo
|
||||
Parameters: ~
|
||||
• {start} (`string`)
|
||||
• {middle} (`string`)
|
||||
• {end_} (`string`)
|
||||
• {end} (`string`)
|
||||
• {flags} (`string?`)
|
||||
• {skip} (`string|function?`)
|
||||
• {stopline} (`integer?`)
|
||||
@ -8524,7 +8524,7 @@ searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline} [, {ti
|
||||
Parameters: ~
|
||||
• {start} (`string`)
|
||||
• {middle} (`string`)
|
||||
• {end_} (`string`)
|
||||
• {end} (`string`)
|
||||
• {flags} (`string?`)
|
||||
• {skip} (`string|function?`)
|
||||
• {stopline} (`integer?`)
|
||||
@ -9840,7 +9840,7 @@ slice({expr}, {start} [, {end}]) *slice()*
|
||||
Parameters: ~
|
||||
• {expr} (`any`)
|
||||
• {start} (`integer`)
|
||||
• {end_} (`integer?`)
|
||||
• {end} (`integer?`)
|
||||
|
||||
Return: ~
|
||||
(`any`)
|
||||
|
@ -134,6 +134,15 @@ local API_TYPES = {
|
||||
void = '',
|
||||
}
|
||||
|
||||
--- @param s string
|
||||
--- @return string
|
||||
local function luaescape(s)
|
||||
if LUA_KEYWORDS[s] then
|
||||
return s .. '_'
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
--- @param x string
|
||||
--- @param sep? string
|
||||
--- @return string[]
|
||||
@ -208,7 +217,7 @@ local function render_fun_sig(f, params)
|
||||
--- @param v [string,string]
|
||||
--- @return string
|
||||
function(v)
|
||||
return v[1]
|
||||
return luaescape(v[1])
|
||||
end,
|
||||
params
|
||||
),
|
||||
@ -224,7 +233,6 @@ local function render_fun_sig(f, params)
|
||||
end
|
||||
|
||||
--- Uniquify names
|
||||
--- Fix any names that are lua keywords
|
||||
--- @param params [string,string,string][]
|
||||
--- @return [string,string,string][]
|
||||
local function process_params(params)
|
||||
@ -232,9 +240,6 @@ local function process_params(params)
|
||||
local sfx = 1
|
||||
|
||||
for _, p in ipairs(params) do
|
||||
if LUA_KEYWORDS[p[1]] then
|
||||
p[1] = p[1] .. '_'
|
||||
end
|
||||
if seen[p[1]] then
|
||||
p[1] = p[1] .. sfx
|
||||
sfx = sfx + 1
|
||||
@ -389,10 +394,10 @@ local function render_api_meta(_f, fun, write)
|
||||
local param_names = {} --- @type string[]
|
||||
local params = process_params(fun.params)
|
||||
for _, p in ipairs(params) do
|
||||
param_names[#param_names + 1] = p[1]
|
||||
local pdesc = p[3]
|
||||
local pname, ptype, pdesc = luaescape(p[1]), p[2], p[3]
|
||||
param_names[#param_names + 1] = pname
|
||||
if pdesc then
|
||||
local s = '--- @param ' .. p[1] .. ' ' .. p[2] .. ' '
|
||||
local s = '--- @param ' .. pname .. ' ' .. ptype .. ' '
|
||||
local pdesc_a = split(vim.trim(norm_text(pdesc)))
|
||||
write(s .. pdesc_a[1])
|
||||
for i = 2, #pdesc_a do
|
||||
@ -402,7 +407,7 @@ local function render_api_meta(_f, fun, write)
|
||||
write('--- ' .. pdesc_a[i])
|
||||
end
|
||||
else
|
||||
write('--- @param ' .. p[1] .. ' ' .. p[2])
|
||||
write('--- @param ' .. pname .. ' ' .. ptype)
|
||||
end
|
||||
end
|
||||
|
||||
@ -494,7 +499,7 @@ local function render_eval_meta(f, fun, write)
|
||||
local req_args = type(fun.args) == 'table' and fun.args[1] or fun.args or 0
|
||||
|
||||
for i, param in ipairs(params) do
|
||||
local pname, ptype = param[1], param[2]
|
||||
local pname, ptype = luaescape(param[1]), param[2]
|
||||
local optional = (pname ~= '...' and i > req_args) and '?' or ''
|
||||
write(fmt('--- @param %s%s %s', pname, optional, ptype))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user