summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md5
-rw-r--r--script/parser/luadoc.lua13
-rw-r--r--test/type_inference/init.lua21
3 files changed, 37 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md
index c9b64e0f..5c99dd5e 100644
--- a/changelog.md
+++ b/changelog.md
@@ -28,6 +28,11 @@
local n2 = f(0) -- `n2` is `number`
local n3 = f(0, 0) -- `n3` is `string`
```
+* `CHG` semicolons and parentheses can be used in `DocTable`
+ ```lua
+ ---@type { x: fun():boolean; y: boolean }
+ ---@type { (x: fun():boolean), y: boolean }
+ ```
* `CHG` improve experience for diagnostics and semantic-tokens
* `FIX` diagnostics flash when opening a file
* `FIX` sometimes workspace diagnostics are not triggered
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index fdf7718c..06cd5511 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -50,7 +50,7 @@ EChar <- 'a' -> ea
/ ([0-9] [0-9]? [0-9]?) -> Char10
/ ('u{' {X16*} '}') -> CharUtf8
Symbol <- ({} {
- [:|,<>()?+#{}]
+ [:|,;<>()?+#{}]
/ '[]'
/ '...'
/ '['
@@ -286,6 +286,11 @@ local function parseTable(parent)
}
do
+ local needCloseParen
+ if checkToken('symbol', '(', 1) then
+ nextToken()
+ needCloseParen = true
+ end
field.name = parseName('doc.field.name', field)
or parseIndexField('doc.field.name', field)
if not field.name then
@@ -312,10 +317,14 @@ local function parseTable(parent)
break
end
field.finish = getFinish()
+ if needCloseParen then
+ nextSymbolOrError ')'
+ end
end
typeUnit.fields[#typeUnit.fields+1] = field
- if checkToken('symbol', ',', 1) then
+ if checkToken('symbol', ',', 1)
+ or checkToken('symbol', ';', 1) then
nextToken()
else
nextSymbolOrError('}')
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 434307a2..8cf98da5 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -3043,3 +3043,24 @@ local b
local <?x?> = a[b]
]]
+
+TEST 'number' [[
+---@type {x: string ; y: boolean; z: number}
+local t
+
+local <?z?> = t.z
+]]
+
+TEST 'fun():number, boolean' [[
+---@type {f: fun():number, boolean}
+local t
+
+local <?f?> = t.f
+]]
+
+TEST 'fun():number' [[
+---@type {(f: fun():number), x: boolean}
+local t
+
+local <?f?> = t.f
+]]