From 8d55cc218cfed54136677398ca76c45987b15f29 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sun, 24 Nov 2024 10:40:56 +0000 Subject: feat(keysets): teach Union and LuaRefOf --- scripts/gen_eval_files.lua | 53 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'scripts/gen_eval_files.lua') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index a9431ae2e5..498bf6b26f 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -47,6 +47,18 @@ local LUA_API_RETURN_OVERRIDES = { nvim_win_get_config = 'vim.api.keyset.win_config', } +local LUA_API_KEYSET_OVERRIDES = { + create_autocmd = { + callback = 'string|(fun(args: vim.api.keyset.create_autocmd.callback_args): boolean?)', + }, +} + +local LUA_API_PARAM_OVERRIDES = { + nvim_create_user_command = { + command = 'string|fun(args: vim.api.keyset.create_user_command.command_args)', + }, +} + local LUA_META_HEADER = { '--- @meta _', '-- THIS FILE IS GENERATED', @@ -118,7 +130,7 @@ local API_TYPES = { LuaRef = 'function', Dict = 'table', Float = 'number', - HLGroupID = 'number|string', + HLGroupID = 'integer|string', void = '', } @@ -133,6 +145,10 @@ end --- @param t string --- @return string local function api_type(t) + if vim.startswith(t, '*') then + return api_type(t:sub(2)) .. '?' + end + local as0 = t:match('^ArrayOf%((.*)%)') if as0 then local as = split(as0, ', ') @@ -149,6 +165,33 @@ local function api_type(t) return 'table' end + local u = t:match('^Union%((.*)%)') + if u then + local us = vim.split(u, ',%s*') + return table.concat(vim.tbl_map(api_type, us), '|') + end + + local l = t:match('^LuaRefOf%((.*)%)') + if l then + --- @type string + l = l:gsub('%s+', ' ') + --- @type string?, string? + local as, r = l:match('%((.*)%),%s*(.*)') + if not as then + --- @type string + as = assert(l:match('%((.*)%)')) + end + + local as1 = {} --- @type string[] + for a in vim.gsplit(as, ',%s') do + local a1 = vim.split(a, '%s+', { trimempty = true }) + local nm = a1[2]:gsub('%*(.*)$', '%1?') + as1[#as1 + 1] = nm .. ': ' .. api_type(a1[1]) + end + + return ('fun(%s)%s'):format(table.concat(as1, ', '), r and ': ' .. api_type(r) or '') + end + return API_TYPES[t] or t end @@ -251,11 +294,13 @@ local function get_api_meta() sees[#sees + 1] = see.desc end + local pty_overrides = LUA_API_PARAM_OVERRIDES[fun.name] or {} + local params = {} --- @type [string,string][] for _, p in ipairs(fun.params) do params[#params + 1] = { p.name, - api_type(p.type), + api_type(pty_overrides[p.name] or p.type), not deprecated and p.desc or nil, } end @@ -382,9 +427,11 @@ local function get_api_keysets_meta() local keysets = metadata.keysets for _, k in ipairs(keysets) do + local pty_overrides = LUA_API_KEYSET_OVERRIDES[k.name] or {} local params = {} for _, key in ipairs(k.keys) do - table.insert(params, { key .. '?', api_type(k.types[key] or 'any') }) + local pty = pty_overrides[key] or k.types[key] or 'any' + table.insert(params, { key .. '?', api_type(pty) }) end ret[k.name] = { signature = 'NA', -- cgit From 2550b5e9bdc0b4d19bc0313626ed0d3b928e491c Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Fri, 6 Dec 2024 12:08:46 -0600 Subject: docs: do not escape Lua keywords #31467 --- scripts/gen_eval_files.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'scripts/gen_eval_files.lua') 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 -- cgit From f9dd6826210335d8b37455002d767d1b37c09ce4 Mon Sep 17 00:00:00 2001 From: Colin Kennedy Date: Wed, 11 Dec 2024 01:01:14 -0800 Subject: docs(annotations): added `---@generic` support --- scripts/gen_eval_files.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'scripts/gen_eval_files.lua') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index de9df5054f..0970ae503a 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -496,6 +496,10 @@ local function render_eval_meta(f, fun, write) end end + for _, text in ipairs(vim.fn.reverse(fun.generics or {})) do + write(fmt('--- @generic %s', text)) + end + local req_args = type(fun.args) == 'table' and fun.args[1] or fun.args or 0 for i, param in ipairs(params) do -- cgit From b51110f4a11af114401e626cd4c1f1aec23e81c5 Mon Sep 17 00:00:00 2001 From: Shihua Zeng <76579810+Bekaboo@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:56:10 -0500 Subject: docs(api): return type of nvim_get_keymap() #31708 --- scripts/gen_eval_files.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/gen_eval_files.lua') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index 0970ae503a..f888972f0d 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -26,11 +26,11 @@ local LUA_API_RETURN_OVERRIDES = { nvim_buf_get_command = 'table', nvim_buf_get_extmark_by_id = 'vim.api.keyset.get_extmark_item_by_id', nvim_buf_get_extmarks = 'vim.api.keyset.get_extmark_item[]', - nvim_buf_get_keymap = 'vim.api.keyset.keymap[]', + nvim_buf_get_keymap = 'vim.api.keyset.get_keymap[]', nvim_get_autocmds = 'vim.api.keyset.get_autocmds.ret[]', nvim_get_color_map = 'table', nvim_get_command = 'table', - nvim_get_keymap = 'vim.api.keyset.keymap[]', + nvim_get_keymap = 'vim.api.keyset.get_keymap[]', nvim_get_mark = 'vim.api.keyset.get_mark', -- Can also return table, however we need to -- cgit From 34e2185022ab698827b72751d77e218a1b6b6afe Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 10 Jan 2025 10:20:43 +0000 Subject: fix(options): better handling of empty values Problem: Whether an option is allowed to be empty isn't well defined and isn't properly checked. Solution: - For non-list string options, explicitly check the option value if it is empty. - Annotate non-list string options that can accept an empty value. - Adjust command completion to ignore the empty value. - Render values in Lua meta files --- scripts/gen_eval_files.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'scripts/gen_eval_files.lua') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index f888972f0d..58d3eeeadc 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -666,7 +666,16 @@ local function render_option_meta(_f, opt, write) write('--- ' .. l) end - write('--- @type ' .. OPTION_TYPES[opt.type]) + if opt.type == 'string' and not opt.list and opt.values then + local values = {} --- @type string[] + for _, e in ipairs(opt.values) do + values[#values + 1] = fmt("'%s'", e) + end + write('--- @type ' .. table.concat(values, '|')) + else + write('--- @type ' .. OPTION_TYPES[opt.type]) + end + write('vim.o.' .. opt.full_name .. ' = ' .. render_option_default(opt.defaults)) if opt.abbreviation then write('vim.o.' .. opt.abbreviation .. ' = vim.o.' .. opt.full_name) -- cgit From 6aa42e8f92bd8bea49b7b2accfe4ab67a5344e41 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 24 Jan 2025 13:01:25 +0000 Subject: fix: resolve all remaining LuaLS diagnostics --- scripts/gen_eval_files.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'scripts/gen_eval_files.lua') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index 58d3eeeadc..aaf76a0411 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -72,6 +72,10 @@ local LUA_API_META_HEADER = { '-- DO NOT EDIT', "error('Cannot require a meta file')", '', + '--- This file embeds vimdoc as the function descriptions', + '--- so ignore any doc related errors.', + '--- @diagnostic disable: undefined-doc-name,luadoc-miss-symbol', + '', 'vim.api = {}', } -- cgit