diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-10 03:12:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-10 03:12:05 +0800 |
commit | 4e0a890060aea1eb54b14b3a77cba8fc42ceeebb (patch) | |
tree | 0ba13f7a859f2ea850f09774936b15d3fb1d971c /script | |
parent | 88b155930b1fe6a8cf086c55ea3b108c8b1f0e73 (diff) | |
download | lua-language-server-4e0a890060aea1eb54b14b3a77cba8fc42ceeebb.zip |
supports `---@type (string|integer)[]`
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/luadoc.lua | 11 | ||||
-rw-r--r-- | script/vm/infer.lua | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 6adbfa68..f9cd3db0 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -598,6 +598,16 @@ local function parseBoolean(parent) return boolean end +local function parseParen(parent) + if not checkToken('symbol', '(', 1) then + return + end + nextToken() + local tp = parseType(parent) + nextSymbolOrError(')') + return tp +end + function parseTypeUnit(parent) local result = parseFunction(parent) or parseTable(parent) @@ -605,6 +615,7 @@ function parseTypeUnit(parent) or parseInteger(parent) or parseBoolean(parent) or parseDots('doc.type.name', parent) + or parseParen(parent) if not result then local literal = checkToken('symbol', '`', 1) if literal then diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 04fd01ca..1f2e0123 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -111,7 +111,11 @@ local viewNodeSwitch = util.switch() : case 'doc.type.array' : call(function (source, infer) infer._hasClass = true - return m.getInfer(source.node):view() .. '[]' + local view = m.getInfer(source.node):view() + if source.node.type == 'doc.type' then + view = '(' .. view .. ')' + end + return view .. '[]' end) : case 'doc.type.table' : call(function (source, infer) |