summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md4
-rw-r--r--script/parser/guide.lua12
-rw-r--r--script/parser/luadoc.lua5
-rw-r--r--test/type_inference/init.lua15
4 files changed, 32 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index bf9540f2..f3c2511d 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,8 +1,8 @@
# changelog
## 1.17.1
-* `CHG` intelli-scense: improve infer cross `table<K, V>`, which `K` and `V` is generic.
-* `CHG` intelli-scense: improve infer cross `pairs`
+* `CHG` intelli-scense: improve infer across `table<K, V>` and `V[]`.
+* `CHG` intelli-scense: improve infer across `pairs` and `ipairs`
* `FIX` [#398](https://github.com/sumneko/lua-language-server/issues/398)
## 1.17.0
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 16aea8f1..b2b1e583 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -99,6 +99,7 @@ m.childMap = {
['doc.generic'] = {'#generics', 'comment'},
['doc.generic.object'] = {'generic', 'extends', 'comment'},
['doc.vararg'] = {'vararg', 'comment'},
+ ['doc.type.array'] = {'node'},
['doc.type.table'] = {'node', 'key', 'value', 'comment'},
['doc.type.function'] = {'#args', '#returns', 'comment'},
['doc.type.typeliteral'] = {'node'},
@@ -1670,6 +1671,16 @@ local function stepRefOfGenericCrossTable(status, doc, typeName)
return function (obj)
return nil
end
+ elseif typeUnit.type == 'doc.type.array' then
+ return function (obj)
+ local childStatus = m.status(status)
+ m.searchRefs(childStatus, obj, 'def')
+ for _, res in ipairs(childStatus.results) do
+ if res.type == 'doc.type.array' then
+ return res.node
+ end
+ end
+ end
end
end
return function (obj)
@@ -1702,6 +1713,7 @@ local function stepRefOfGeneric(status, typeUnit, args, mode)
end
local docArg = m.getParentType(typeName, 'doc.type.arg')
or m.getParentType(typeName, 'doc.param')
+ or m.getParentType(typeName, 'doc.type.array')
if not docArg then
goto CONTINUE
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index f30d47b4..7684ac1f 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -256,7 +256,7 @@ local function nextSymbolOrError(symbol)
return false
end
-local function parseTypeUnitArray(node)
+local function parseTypeUnitArray(parent, node)
if not checkToken('symbol', '[]', 1) then
return nil
end
@@ -266,6 +266,7 @@ local function parseTypeUnitArray(node)
start = node.start,
finish = getFinish(),
node = node,
+ parent = parent,
}
node.parent = result
return result
@@ -413,7 +414,7 @@ local function parseTypeUnit(parent, content)
end
result.parent = parent
while true do
- local newResult = parseTypeUnitArray(result)
+ local newResult = parseTypeUnitArray(parent, result)
or parseTypeUnitTable(parent, result)
if not newResult then
break
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 725b19fe..c211283a 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -547,3 +547,18 @@ local t
for k, <?v?> in pairs(t) do
end
]]
+
+TEST 'boolean' [[
+---@generic T: table, V
+---@param t T
+---@return fun(table: V[], i?: integer):integer, V
+---@return T
+---@return integer i
+local function ipairs(t) end
+
+---@type boolean[]
+local t
+
+for _, <?v?> in ipairs(t) do
+end
+]]