summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/eachRef.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-11 21:24:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-11 21:24:53 +0800
commit4caf0cac1caf6e8567016424dfa103af27f097b7 (patch)
treea990c3a60403ea276c1bfa549d26c72141e614cc /server-beta/src/searcher/eachRef.lua
parent025b80013795760483e75fc2487e439a0f62cfeb (diff)
downloadlua-language-server-4caf0cac1caf6e8567016424dfa103af27f097b7.zip
跨越 link
Diffstat (limited to 'server-beta/src/searcher/eachRef.lua')
-rw-r--r--server-beta/src/searcher/eachRef.lua76
1 files changed, 49 insertions, 27 deletions
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 21e9b401..82ed4269 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -6,10 +6,16 @@ local searcher = require 'searcher.searcher'
local function ofCall(func, index, callback)
searcher.eachRef(func, function (info)
local src = info.source
- local funcDef = src.value
- if funcDef and funcDef.returns then
+ local returns
+ if info.mode == 'main' then
+ returns = src.returns
+ else
+ local funcDef = src.value
+ returns = funcDef and funcDef.returns
+ end
+ if returns then
-- 搜索函数第 index 个返回值
- for _, rtn in ipairs(funcDef.returns) do
+ for _, rtn in ipairs(returns) do
local val = rtn[index]
if val then
callback {
@@ -23,6 +29,23 @@ local function ofCall(func, index, callback)
end)
end
+local function ofCallSelect(call, index, callback)
+ local slc = call.parent
+ if slc.index == index then
+ searcher.eachRef(slc.parent, callback)
+ return
+ end
+ if call.extParent then
+ for i = 1, #call.extParent do
+ slc = call.extParent[i]
+ if slc.index == index then
+ searcher.eachRef(slc.parent, callback)
+ return
+ end
+ end
+ end
+end
+
local function ofReturn(rtn, index, callback)
local func = guide.getParentFunction(rtn)
if not func then
@@ -35,20 +58,7 @@ local function ofReturn(rtn, index, callback)
if not call or call.type ~= 'call' then
return
end
- local slc = call.parent
- if slc.index == index then
- searcher.eachRef(slc.parent, callback)
- return
- end
- if call.extParent then
- for i = 1, #call.extParent do
- slc = call.extParent[i]
- if slc.index == index then
- searcher.eachRef(slc.parent, callback)
- return
- end
- end
- end
+ ofCallSelect(call, index, callback)
end)
end
@@ -80,7 +90,7 @@ local function ofSpecialCall(call, func, index, callback)
if not files.eq(uri, myUri) then
local ast = files.getAst(uri)
if ast then
- searcher.eachRef(ast.ast, callback)
+ ofCall(ast.ast, 1, callback)
end
end
end
@@ -369,16 +379,28 @@ local function ofGoTo(source, callback)
end
local function ofMain(source, callback)
- if source.returns then
- for _, rtn in ipairs(source.returns) do
- local val = rtn[1]
- if val then
- callback {
- source = val,
- mode = 'return',
- }
- searcher.eachRef(val, callback)
+ callback {
+ source = source,
+ mode = 'main',
+ }
+ local myUri = source.uri
+ local uris = files.findLinkTo(myUri)
+ if not uris then
+ return
+ end
+ for _, uri in ipairs(uris) do
+ local ast = files.getAst(uri)
+ if ast then
+ local links = searcher.getLinks(ast.ast)
+ if links then
+ for linkUri, calls in pairs(links) do
+ if files.eq(linkUri, myUri) then
+ for i = 1, #calls do
+ ofCallSelect(calls[i], 1, callback)
+ end
+ end
end
+ end
end
end
end