summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-05-08 17:40:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-05-08 17:40:33 +0800
commitca6a5b1ab080b9bebb850da56dcc37b6d17db144 (patch)
tree0997c60fa5cfbef4a3a5ae500528e9ce3b152c64
parent0af503e8ebe11fd6226c0363d40473007dbe1f6d (diff)
downloadlua-language-server-ca6a5b1ab080b9bebb850da56dcc37b6d17db144.zip
cleanup
-rw-r--r--script/core/linker.lua2
-rw-r--r--script/core/searcher.lua48
2 files changed, 19 insertions, 31 deletions
diff --git a/script/core/linker.lua b/script/core/linker.lua
index af3be6ee..f8c102d1 100644
--- a/script/core/linker.lua
+++ b/script/core/linker.lua
@@ -395,6 +395,7 @@ local function compileLink(source)
if not nodeID then
return
end
+ getLink(id).call = source
-- 将 call 映射到 node#1 上
do
local select1ID = ('%s%s%s%s'):format(
@@ -446,7 +447,6 @@ local function compileLink(source)
)
pushForward(id, callID)
pushBackward(callID, id)
- getLink(id).call = source.vararg
end
end
if source.type == 'doc.type.function' then
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 4a78dca8..aea13ed5 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -169,20 +169,18 @@ function m.searchRefsByID(status, uri, expect, mode)
return
end
local root = ast.ast
+ local searchStep
linker.compileLinks(root)
status.id = expect
local mark = status.mark
- local queueIDs = {}
- local queueFields = {}
- local queueCalls = {}
local queueIndex = 0
-- 缓存过程中的泛型,以泛型关联表为key
local genericStashMap = {}
- local function search(id, field, call)
+ local function search(id, field)
local fieldLen
if field then
local _, len = field:gsub(linker.SPLIT_CHAR, '')
@@ -195,30 +193,28 @@ function m.searchRefsByID(status, uri, expect, mode)
end
mark[id] = fieldLen
queueIndex = queueIndex + 1
- queueIDs[queueIndex] = id
- queueFields[queueIndex] = field
- queueCalls[queueIndex] = call
+ searchStep(id, field)
end
- local function checkLastID(id, field, callinfo)
+ local function checkLastID(id, field)
local lastID = linker.getLastID(id)
if lastID then
local newField = id:sub(#lastID + 1)
if field then
newField = newField .. field
end
- search(lastID, newField, callinfo)
+ search(lastID, newField)
end
end
- local function searchID(id, field, callinfo)
+ local function searchID(id, field)
if not id then
return
end
if field then
id = id .. field
end
- search(id, nil, callinfo)
+ search(id, nil)
end
local function searchFunction(id)
@@ -342,24 +338,14 @@ function m.searchRefsByID(status, uri, expect, mode)
end
end
- search(expect)
- searchFunction(expect)
-
- for _ = 1, 1000 do
- if queueIndex <= 0 then
- return
+ local stepCount = 0
+ function searchStep(id, field)
+ stepCount = stepCount + 1
+ if stepCount > 1000 then
+ error('too large')
end
- local id = queueIDs[queueIndex]
- local field = queueFields[queueIndex]
- local call = queueCalls[queueIndex]
- queueIndex = queueIndex - 1
-
local link = linker.getLinkByID(root, id)
if link then
- if link.call then
- callStash[#callStash+1] = link.call
- end
- call = link.call or call
if field == nil and link.sources then
for _, source in ipairs(link.sources) do
m.pushResult(status, mode, source)
@@ -367,12 +353,12 @@ function m.searchRefsByID(status, uri, expect, mode)
end
if link.forward then
for _, forwardID in ipairs(link.forward) do
- searchID(forwardID, field, call)
+ searchID(forwardID, field)
end
end
if link.backward and (mode == 'ref' or field) then
for _, backwardID in ipairs(link.backward) do
- searchID(backwardID, field, call)
+ searchID(backwardID, field)
end
end
@@ -381,9 +367,11 @@ function m.searchRefsByID(status, uri, expect, mode)
genericResolve(link.sources[1], field)
end
end
- checkLastID(id, field, call)
+ checkLastID(id, field)
end
- error('too large')
+
+ search(expect)
+ searchFunction(expect)
end
---搜索对象的引用