summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-03-15 15:54:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-03-15 15:54:18 +0800
commit4e68872ea96a53f9c7ad5e11c83794b92f477fb4 (patch)
treee18475aefccae62be35ba93d6a600e036fd0cdab /script/core
parentba041ed17bac8a00a0e83ee289e7a257bf6f3d8b (diff)
downloadlua-language-server-4e68872ea96a53f9c7ad5e11c83794b92f477fb4.zip
#close 289
Diffstat (limited to 'script/core')
-rw-r--r--script/core/guide.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/script/core/guide.lua b/script/core/guide.lua
index c05d5fb0..7ef69380 100644
--- a/script/core/guide.lua
+++ b/script/core/guide.lua
@@ -1399,6 +1399,10 @@ function m.getCallAndArgIndex(callarg)
end
end
local call = callargs.parent
+ local node = call.node
+ if node.type == 'getmethod' then
+ index = index + 1
+ end
return call, index
end
@@ -2584,6 +2588,69 @@ function m.checkSameSimpleAsKeyOrValueInForParis(status, ref, start, pushQueue)
end
end
+---
+---@param func core.guide.object
+---@param argIndex integer
+---@return integer?
+local function findGenericFromArgIndexToReturnIndex(func, argIndex)
+ if not func.bindDocs then
+ return nil
+ end
+ local paramType
+ for _, doc in ipairs(func.bindDocs) do
+ if doc.type == 'doc.param' then
+ if doc.extends.paramIndex == argIndex then
+ paramType = doc.extends
+ break
+ end
+ end
+ end
+ if not paramType then
+ return nil
+ end
+ for _, typeUnit in ipairs(paramType.types) do
+ if typeUnit.typeGeneric then
+ local generic = typeUnit.typeGeneric[typeUnit[1]]
+ if generic then
+ for _, typeName in ipairs(generic) do
+ local docType = typeName.parent
+ if docType.returnIndex then
+ return docType.returnIndex
+ end
+ end
+ end
+ end
+ end
+ return nil
+end
+
+function m.checkSameSimpleAsCallArg(status, ref, start, pushQueue)
+ local call, index = m.getCallAndArgIndex(ref)
+ if not call then
+ return
+ end
+ local newStatus = m.status(status)
+ m.searchRefs(newStatus, call.node, 'def')
+ for _, func in ipairs(newStatus.results) do
+ local rindex = findGenericFromArgIndexToReturnIndex(func, index)
+ if rindex then
+ if rindex == 1 then
+ if call.parent.type == 'select' then
+ pushQueue(call.parent.parent, start, true)
+ end
+ else
+ if call.extParent then
+ for _, slt in ipairs(call.extParent) do
+ if slt.index == rindex then
+ pushQueue(slt.parent, start, true)
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
local function hasTypeName(doc, name)
if doc.type == 'doc.type' then
for _, tunit in ipairs(doc.types) do
@@ -2858,6 +2925,8 @@ function m.checkSameSimple(status, simple, ref, start, force, mode, pushQueue)
m.checkSameSimpleAsSetValue(status, ref, i, pushQueue)
-- 检查形如 for k,v in pairs()/ipairs() do end 的情况
m.checkSameSimpleAsKeyOrValueInForParis(status, ref, i, pushQueue)
+ -- 检查自己是函数参数的情况(泛型) local x = call(V)
+ m.checkSameSimpleAsCallArg(status, ref, i, pushQueue)
end
end
if i == #simple then