diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-07-22 17:33:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-07-22 17:33:43 +0800 |
commit | 51fd9b20bb56541eaf7c8e70beb9eb65192e7687 (patch) | |
tree | 1a5e3e4b086be6437a69e8a2055a9af019a030be | |
parent | c652ff3836785b7c8d6da83d3544a9fef09da752 (diff) | |
download | lua-language-server-51fd9b20bb56541eaf7c8e70beb9eb65192e7687.zip |
暂存
-rw-r--r-- | script-beta/parser/guide.lua | 29 | ||||
-rw-r--r-- | script-beta/vm/eachDef.lua | 11 |
2 files changed, 24 insertions, 16 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 diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 92982660..65878ebf 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -79,10 +79,15 @@ function m.eachDef(source, results) return results end -function vm.eachDef(source, callback) +function vm.getDefs(source) local cache = vm.cache.eachDef[source] or m.eachDef(source) vm.cache.eachDef[source] = cache - for i = 1, #cache do - callback(cache[i]) + return cache +end + +function vm.eachDef(source, callback) + local results = vm.getDefs(source) + for i = 1, #results do + callback(results[i]) end end |