aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2024-12-06 12:08:46 -0600
committerGitHub <noreply@github.com>2024-12-06 10:08:46 -0800
commit2550b5e9bdc0b4d19bc0313626ed0d3b928e491c (patch)
treef07b04d3d85393f868f9af50448e3fe59b4c8d99 /scripts
parentba7370a902abc1ca533f8ebf70f708e16a2a64c2 (diff)
downloadrneovim-2550b5e9bdc0b4d19bc0313626ed0d3b928e491c.tar.gz
rneovim-2550b5e9bdc0b4d19bc0313626ed0d3b928e491c.tar.bz2
rneovim-2550b5e9bdc0b4d19bc0313626ed0d3b928e491c.zip
docs: do not escape Lua keywords #31467
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gen_eval_files.lua25
1 files changed, 15 insertions, 10 deletions
diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua
index 498bf6b26f..de9df5054f 100755
--- a/scripts/gen_eval_files.lua
+++ b/scripts/gen_eval_files.lua
@@ -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