diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-25 20:13:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-25 20:13:42 +0800 |
commit | 2c6f0f9bf83f9a44c466aaf0d45ed9f8eab6c117 (patch) | |
tree | 96b11b2863b0a1e10158e6ad6cc5df3b8fb74716 | |
parent | 7b809496a5a4be6a182d715b264493cb39c98674 (diff) | |
download | lua-language-server-2c6f0f9bf83f9a44c466aaf0d45ed9f8eab6c117.zip |
resolve #1226
semicolons and parentheses can be used in `DocTable`
-rw-r--r-- | changelog.md | 5 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 13 | ||||
-rw-r--r-- | test/type_inference/init.lua | 21 |
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 +]] |