summaryrefslogtreecommitdiff
path: root/script-beta/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-22 17:33:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-22 17:33:43 +0800
commit51fd9b20bb56541eaf7c8e70beb9eb65192e7687 (patch)
tree1a5e3e4b086be6437a69e8a2055a9af019a030be /script-beta/parser
parentc652ff3836785b7c8d6da83d3544a9fef09da752 (diff)
downloadlua-language-server-51fd9b20bb56541eaf7c8e70beb9eb65192e7687.zip
暂存
Diffstat (limited to 'script-beta/parser')
-rw-r--r--script-beta/parser/guide.lua29
1 files changed, 16 insertions, 13 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 5eff3e1d..a345beb3 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -315,6 +315,7 @@ end
--- 遍历所有包含offset的source
function m.eachSourceContain(ast, offset, callback)
local list = { ast }
+ local mark = {}
while true do
local len = #list
if len == 0 then
@@ -322,14 +323,17 @@ function m.eachSourceContain(ast, offset, callback)
end
local obj = list[len]
list[len] = nil
- if m.isInRange(obj, offset) then
- if m.isContain(obj, offset) then
- local res = callback(obj)
- if res ~= nil then
- return res
+ if not mark[obj] then
+ mark[obj] = true
+ if m.isInRange(obj, offset) then
+ if m.isContain(obj, offset) then
+ local res = callback(obj)
+ if res ~= nil then
+ return res
+ end
end
+ m.addChilds(list, obj, m.childMap)
end
- m.addChilds(list, obj, m.childMap)
end
end
end
@@ -338,14 +342,9 @@ end
function m.eachSourceType(ast, type, callback)
local cache = ast.typeCache
if not cache then
- local mark = {}
cache = {}
ast.typeCache = cache
m.eachSource(ast, function (source)
- if mark[source] then
- return
- end
- mark[source] = true
local tp = source.type
if not tp then
return
@@ -370,6 +369,7 @@ end
--- 遍历所有的source
function m.eachSource(ast, callback)
local list = { ast }
+ local mark = {}
local index = 1
while true do
local obj = list[index]
@@ -378,8 +378,11 @@ function m.eachSource(ast, callback)
end
list[index] = false
index = index + 1
- callback(obj)
- m.addChilds(list, obj, m.childMap)
+ if not mark[obj] then
+ mark[obj] = true
+ callback(obj)
+ m.addChilds(list, obj, m.childMap)
+ end
end
end