summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/parser/luadoc.lua11
-rw-r--r--script/vm/infer.lua6
-rw-r--r--test/type_inference/init.lua5
4 files changed, 22 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index 61a81c69..d74b5716 100644
--- a/changelog.md
+++ b/changelog.md
@@ -6,6 +6,7 @@
+ `type-check`: removed for now
+ `no-implicit-any`: renamed to `no-unknown`
* `CHG` formatter: no longer need` --preview`
+* `CHG` `LuaDoc`: supports `---@type (string|integer)[]`
* `FIX` semantic: color of `function`
* `FIX` [#1027](https://github.com/sumneko/lua-language-server/issues/1027)
* `FIX` [#1028](https://github.com/sumneko/lua-language-server/issues/1028)
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)
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 4d1cfb4a..d199f79b 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1434,3 +1434,8 @@ local t = { 'x' }
local <?x?> = t[#t]
]]
+
+TEST '(string|integer)[]' [[
+---@type (string|integer)[]
+local <?x?>
+]]