diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-31 15:05:00 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-31 15:05:00 +0800 |
commit | 709d4d828978ecd787dbbf108b04e985c4afc0a4 (patch) | |
tree | f2184e5193a0291cddfe8eaf56cf771f89041da7 | |
parent | 1ce3f9689ff1b072385b7af69c588f951f2d4098 (diff) | |
download | lua-language-server-709d4d828978ecd787dbbf108b04e985c4afc0a4.zip |
doc.type.function 支持 ?
-rw-r--r-- | script-beta/core/hover/arg.lua | 6 | ||||
-rw-r--r-- | script-beta/core/hover/name.lua | 1 | ||||
-rw-r--r-- | script-beta/core/hover/return.lua | 5 | ||||
-rw-r--r-- | script-beta/parser/luadoc.lua | 11 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 11 |
5 files changed, 30 insertions, 4 deletions
diff --git a/script-beta/core/hover/arg.lua b/script-beta/core/hover/arg.lua index 5dcf94b6..ef5eef57 100644 --- a/script-beta/core/hover/arg.lua +++ b/script-beta/core/hover/arg.lua @@ -90,7 +90,11 @@ local function asDocFunction(source) for i = 1, #source.args do local arg = source.args[i] local name = arg.name[1] - args[i] = ('%s: %s'):format(name, vm.getInferType(arg.extends)) + args[i] = ('%s: %s%s'):format( + name, + vm.getInferType(arg.extends), + arg.optional and '?' or '' + ) end return table.concat(args, ', ') end diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua index 4d5b015c..9f19d8f3 100644 --- a/script-beta/core/hover/name.lua +++ b/script-beta/core/hover/name.lua @@ -71,6 +71,7 @@ end local function asDocFunction(source) local doc = guide.getParentType(source, 'doc.type') + or guide.getParentType(source, 'doc.overload') if not doc or not doc.bindSources then return '' end diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua index 4159e039..a0b4363d 100644 --- a/script-beta/core/hover/return.lua +++ b/script-beta/core/hover/return.lua @@ -126,7 +126,10 @@ local function asDocFunction(source) end local returns = {} for i, rtn in ipairs(source.returns) do - local rtnText = vm.getInferType(rtn) + local rtnText = ('%s%s'):format( + vm.getInferType(rtn), + rtn.optional and '?' or '' + ) if i == 1 then returns[#returns+1] = (' -> %s'):format(rtnText) else diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index ad2dea14..ca4ee25d 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -52,6 +52,7 @@ Symbol <- ({} { / '>' / '(' / ')' + / '?' } {}) -> Symbol ]], { @@ -291,6 +292,10 @@ local function parseTypeUnitFunction() if not arg.extends then break end + if checkToken('symbol', '?', 1) then + nextToken() + arg.optional = true + end arg.finish = getFinish() typeUnit.args[#typeUnit.args+1] = arg if checkToken('symbol', ',', 1) then @@ -303,10 +308,14 @@ local function parseTypeUnitFunction() if checkToken('symbol', ':', 1) then nextToken() while true do - local rtn = parseType(arg) + local rtn = parseType(typeUnit) if not rtn then break end + if checkToken('symbol', '?', 1) then + nextToken() + rtn.optional = true + end typeUnit.returns[#typeUnit.returns+1] = rtn if checkToken('symbol', ',', 1) then nextToken() diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index 6c91a47c..75750f78 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -1209,8 +1209,17 @@ print(<?f?>) ]] [[ (2 个定义,2 个原型) -(1) function (y: boolean) (1) function f(x: number, y: boolean, z: string) +(1) function f(y: boolean) +]] + +TEST [[ +---@type fun(x: boolean?):boolean? +local <?f?> +]] +[[ +function f(x: boolean?) + -> boolean? ]] do return end |