summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-14 16:49:48 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-14 16:49:48 +0800
commit4ddea4e9386ab0b0ec9583e6c468b52a0d7a8958 (patch)
treeb58dc78883973aeea2e4ee5d113c441454497582
parent113ddccfec2264eb0c500a396bb4bb7ec6729373 (diff)
downloadlua-language-server-4ddea4e9386ab0b0ec9583e6c468b52a0d7a8958.zip
fix infer of infer of `---@type {}[]`
-rw-r--r--changelog.md3
-rw-r--r--script/parser/luadoc.lua8
-rw-r--r--test/type_inference/init.lua7
3 files changed, 14 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index 68ccd4dd..343422e9 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,7 +4,8 @@
* `NEW` `VSCode`: click the status bar icon to operate:
* run workspace diagnostics
* `FIX` `debug.getuservalue` and `debug.setuservalue` should not exist in `Lua 5.1`
-* `FIX` infer of `class[][]`
+* `FIX` infer of `---@type class[][]`
+* `FIX` infer of `---@type {}[]`
## 2.2.3
`2021-7-9`
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index acb19a25..3a3a0984 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -388,10 +388,9 @@ local function parseTypeUnitFunction()
return typeUnit
end
-local function parseTypeUnitLiteralTable(parent)
+local function parseTypeUnitLiteralTable()
local typeUnit = {
type = 'doc.type.ltable',
- parent = parent,
start = getStart(),
fields = {},
}
@@ -451,6 +450,9 @@ local function parseTypeUnit(parent, content)
if content == 'fun' then
result = parseTypeUnitFunction()
end
+ if content == '{' then
+ result = parseTypeUnitLiteralTable()
+ end
if not result then
result = {
type = 'doc.type.name',
@@ -565,7 +567,7 @@ function parseType(parent)
end
elseif tp == 'symbol' and content == '{' then
nextToken()
- local typeUnit = parseTypeUnitLiteralTable(result)
+ local typeUnit = parseTypeUnit(result, content)
if not typeUnit then
break
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index b5d4db16..a3a06bfd 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -894,3 +894,10 @@ TEST 'string[][]' [[
---@type string[][]
local <?t?>
]]
+
+TEST 'table' [[
+---@type {}[]
+local t
+
+local <?v?> = t[1]
+]]