From 24a1c7f556bba35a9c31c2fdd19cf4b8c00a4395 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 28 Sep 2022 09:11:21 +0200 Subject: [PATCH] feat: added support for optional params to lua2dox --- runtime/lua/vim/shared.lua | 4 ++-- scripts/lua2dox.lua | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 1d0a6d5406..5566bd5e35 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -417,8 +417,8 @@ end ---@generic T: table ---@param dst T List which will be modified and appended to ---@param src table List from which values will be inserted ----@param start number|nil Start index on src. Defaults to 1 ----@param finish number|nil Final index on src. Defaults to `#src` +---@param start? number Start index on src. Defaults to 1 +---@param finish? number Final index on src. Defaults to `#src` ---@return T dst function vim.list_extend(dst, src, start, finish) vim.validate({ diff --git a/scripts/lua2dox.lua b/scripts/lua2dox.lua index 7d8e393cc9..d93bb6080f 100644 --- a/scripts/lua2dox.lua +++ b/scripts/lua2dox.lua @@ -410,7 +410,7 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename) local magic_split = string_split(magic, ' ') if magic_split[1] == "generic" then - local generic_name, generic_type = line:match("@generic%s*(%w+)%s*:?%s*(.*)") + local generic_name, generic_type = line:match("@generic%s*(%w+)%s*:?%s*(.*)") if generic_type == "" then generic_type = "any" end @@ -420,6 +420,10 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename) local type_index = 2 if magic_split[1] == 'param' then type_index = type_index + 1 + if magic_split[type_index] and magic_split[2]:find("%?$") then + magic_split[type_index] = magic_split[type_index] .. "|nil" + magic_split[2] = magic_split[2]:sub(1, -2) + end end if magic_split[type_index] then