summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/definition.lua5
-rw-r--r--script/core/infer.lua14
-rw-r--r--script/core/noder.lua32
-rw-r--r--script/core/searcher.lua4
-rw-r--r--test/diagnostics/init.lua5
5 files changed, 40 insertions, 20 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua
index 1693406c..335e178e 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -167,6 +167,11 @@ return function (uri, offset)
goto CONTINUE
end
end
+ if src.type == 'doc.type.name' then
+ if src.typeGeneric then
+ goto CONTINUE
+ end
+ end
results[#results+1] = {
target = src,
diff --git a/script/core/infer.lua b/script/core/infer.lua
index f6ca6499..c66e29c1 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -461,6 +461,7 @@ function m.searchInfers(source, field, mark)
if not source then
return nil
end
+ local isParam = source.parent.type == 'funcargs'
local defs = vm.getDefs(source, field)
local infers = {}
mark = mark or {}
@@ -478,16 +479,9 @@ function m.searchInfers(source, field, mark)
end
end
for _, def in ipairs(defs) do
- searchInfer(def, infers, mark)
- end
- if source.docParam then
- local docType = source.docParam.extends
- if docType and docType.type == 'doc.type' then
- for _, def in ipairs(docType.types) do
- if def.typeGeneric then
- searchInfer(def, infers, mark)
- end
- end
+ if def.typeGeneric and not isParam then
+ else
+ searchInfer(def, infers, mark)
end
end
if source.type == 'doc.type' then
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 545ba729..4318d10c 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -1052,6 +1052,22 @@ compileNodeMap = util.switch()
end)
: case 'doc.type.function'
: call(function (noders, id, source)
+ if source.args then
+ for index, param in ipairs(source.args) do
+ local paramID = sformat('%s%s%s'
+ , id
+ , PARAM_NAME
+ , param.name[1]
+ )
+ pushForward(noders, paramID, getID(param.extends))
+ local indexID = sformat('%s%s%s'
+ , id
+ , PARAM_INDEX
+ , index
+ )
+ pushForward(noders, indexID, getID(param.extends))
+ end
+ end
if source.returns then
for index, rtn in ipairs(source.returns) do
local returnID = sformat('%s%s%s'
@@ -1061,14 +1077,6 @@ compileNodeMap = util.switch()
)
pushForward(noders, returnID, getID(rtn))
end
- for index, param in ipairs(source.args) do
- local paramID = sformat('%s%s%s'
- , id
- , PARAM_NAME
- , param.name[1]
- )
- pushForward(noders, paramID, getID(param.extends))
- end
end
-- @type fun(x: T):T 的情况
local docType = getDocStateWithoutCrossFunction(source)
@@ -1165,7 +1173,13 @@ compileNodeMap = util.switch()
end
end
if source.args then
- for _, arg in ipairs(source.args) do
+ for i, arg in ipairs(source.args) do
+ local indexID = sformat('%s%s%s'
+ , id
+ , PARAM_INDEX
+ , i
+ )
+ pushForward(noders, indexID, getID(arg))
if arg.type == 'local' then
pushForward(noders, getID(arg), sformat('%s%s%s'
, id
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 1407d617..487de982 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -123,6 +123,10 @@ local pushDefResultsMap = util.switch()
: call(function (source, status)
return true
end)
+ : case 'doc.type.name'
+ : call(function (source, status)
+ return source.typeGeneric ~= nil
+ end)
: case 'call'
: call(function (source, status)
if source.node.special == 'rawset' then
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 687027b8..bb613112 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -461,7 +461,7 @@ f(1, 2, 3)
]]
TEST [[
-<!unpack!>(<!1!>)
+<!unpack!>()
]]
TEST [[
@@ -1135,6 +1135,9 @@ return {
}
]]
+-- TODO
+do return end
+
TEST [[
---@param table table
---@param metatable table