diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-28 15:54:36 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-28 15:54:36 +0800 |
commit | 9e875d4ea8ac60939f51771485084c539e66e040 (patch) | |
tree | 384366391332c329834fb4191816e225c46d2865 /server/src/core/hover | |
parent | ef00d018e5f3292dd08deeeabfc77e6c75492a67 (diff) | |
download | lua-language-server-9e875d4ea8ac60939f51771485084c539e66e040.zip |
emmyReturn 支持可选项
Diffstat (limited to 'server/src/core/hover')
-rw-r--r-- | server/src/core/hover/function.lua | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index c5c7a118..5adeeb7e 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -106,30 +106,45 @@ local function buildValueReturns(func) return '' end local strs = {} + local emmys = {} local n = 0 func:eachEmmyReturn(function (emmy) n = n + 1 - local name = '' - if emmy.option and emmy.option.name then - name = emmy.option.name .. ': ' - end - local rtn = func:getReturn(n) - if not rtn then - strs[#strs+1] = name .. 'any' - return - end - strs[#strs+1] = name .. rtn:getType() + emmys[n] = emmy end) if func.returns then - for i = n + 1, #func.returns do - local rtn = func:getReturn(i) + for i, rtn in ipairs(func.returns) do + local emmy = emmys[i] + local option = emmy and emmy.option + if option and option.optional then + if i > 1 then + strs[#strs+1] = ' [' + else + strs[#strs+1] = '[' + end + end + if i > 1 then + strs[#strs+1] = ', ' + end + if option and option.name then + strs[#strs+1] = ('%s: '):format(option.name) + end strs[#strs+1] = rtn:getType() + if option and option.optional == 'self' then + strs[#strs+1] = ']' + end + end + for i = 1, #func.returns do + local emmy = emmys[i] + if emmy and emmy.option and emmy.option.optional == 'after' then + strs[#strs+1] = ']' + end end end if #strs == 0 then strs[1] = 'any' end - return '\n -> ' .. table.concat(strs, ', ') + return '\n -> ' .. table.concat(strs) end ---@param func emmyFunction |