diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-31 15:44:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-31 15:44:41 +0800 |
commit | 09e873bf25f1dbaccd97d4fe7f608dde1fe68028 (patch) | |
tree | c2b6d6c2c595826ec15bdd717ba7343b5176afdb /script-beta | |
parent | 709d4d828978ecd787dbbf108b04e985c4afc0a4 (diff) | |
download | lua-language-server-09e873bf25f1dbaccd97d4fe7f608dde1fe68028.zip |
doc.param 和 doc.return 支持 ?
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/hover/arg.lua | 18 | ||||
-rw-r--r-- | script-beta/core/hover/return.lua | 5 | ||||
-rw-r--r-- | script-beta/parser/luadoc.lua | 8 |
3 files changed, 29 insertions, 2 deletions
diff --git a/script-beta/core/hover/arg.lua b/script-beta/core/hover/arg.lua index ef5eef57..2b7d47d3 100644 --- a/script-beta/core/hover/arg.lua +++ b/script-beta/core/hover/arg.lua @@ -56,6 +56,18 @@ local function asLibrary(source, oop) return table.concat(args) end +local function optionalArg(arg) + if not arg.bindDocs then + return false + end + local name = arg[1] + for _, doc in ipairs(arg.bindDocs) do + if doc.type == 'doc.param' and doc.param[1] == name then + return doc.optional + end + end +end + local function asFunction(source, oop) if not source.args then return '' @@ -65,7 +77,11 @@ local function asFunction(source, oop) local arg = source.args[i] local name = arg.name or guide.getName(arg) if name then - args[i] = ('%s: %s'):format(name, vm.getInferType(arg)) + args[i] = ('%s: %s%s'):format( + name, + vm.getInferType(arg), + optionalArg(arg) and '?' or '' + ) else args[i] = ('%s'):format(vm.getInferType(arg)) end diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua index a0b4363d..589b86b4 100644 --- a/script-beta/core/hover/return.lua +++ b/script-beta/core/hover/return.lua @@ -108,7 +108,10 @@ local function asFunction(source) end if #types > 0 or rtn[1] then local tp = mergeTypes(types) or 'any' - line[#line+1] = tp + line[#line+1] = ('%s%s'):format( + tp, + rtn[1].optional and '?' or '' + ) else break end diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index ca4ee25d..933ce1be 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -453,6 +453,10 @@ local function parseParam() end result.start = getStart() result.extends = parseType(result) + if checkToken('symbol', '?', 1) then + nextToken() + result.optional = true + end if not result.extends then pushError { type = 'LUADOC_MISS_PARAM_EXTENDS', @@ -478,6 +482,10 @@ local function parseReturn() if not result.start then result.start = docType.start end + if checkToken('symbol', '?', 1) then + nextToken() + docType.optional = true + end result.returns[#result.returns+1] = docType if not checkToken('symbol', ',', 1) then break |