Skip to content

Commit 4e0a890

Browse files
committed
supports ---@type (string|integer)[]
1 parent 88b1559 commit 4e0a890

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
+ `type-check`: removed for now
77
+ `no-implicit-any`: renamed to `no-unknown`
88
* `CHG` formatter: no longer need` --preview`
9+
* `CHG` `LuaDoc`: supports `---@type (string|integer)[]`
910
* `FIX` semantic: color of `function`
1011
* `FIX` [#1027](https://github.com/sumneko/lua-language-server/issues/1027)
1112
* `FIX` [#1028](https://github.com/sumneko/lua-language-server/issues/1028)

script/parser/luadoc.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,24 @@ local function parseBoolean(parent)
598598
return boolean
599599
end
600600

601+
local function parseParen(parent)
602+
if not checkToken('symbol', '(', 1) then
603+
return
604+
end
605+
nextToken()
606+
local tp = parseType(parent)
607+
nextSymbolOrError(')')
608+
return tp
609+
end
610+
601611
function parseTypeUnit(parent)
602612
local result = parseFunction(parent)
603613
or parseTable(parent)
604614
or parseString(parent)
605615
or parseInteger(parent)
606616
or parseBoolean(parent)
607617
or parseDots('doc.type.name', parent)
618+
or parseParen(parent)
608619
if not result then
609620
local literal = checkToken('symbol', '`', 1)
610621
if literal then

script/vm/infer.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ local viewNodeSwitch = util.switch()
111111
: case 'doc.type.array'
112112
: call(function (source, infer)
113113
infer._hasClass = true
114-
return m.getInfer(source.node):view() .. '[]'
114+
local view = m.getInfer(source.node):view()
115+
if source.node.type == 'doc.type' then
116+
view = '(' .. view .. ')'
117+
end
118+
return view .. '[]'
115119
end)
116120
: case 'doc.type.table'
117121
: call(function (source, infer)

test/type_inference/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,3 +1434,8 @@ local t = { 'x' }
14341434
14351435
local <?x?> = t[#t]
14361436
]]
1437+
1438+
TEST '(string|integer)[]' [[
1439+
---@type (string|integer)[]
1440+
local <?x?>
1441+
]]

0 commit comments

Comments
 (0)