diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-07-21 21:15:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-07-21 21:15:05 +0800 |
commit | c46e1fd0781750c7d454e7120fe4f6cccce84d8b (patch) | |
tree | 8f32607c9d7f4c09418ad447ab5cbed8383ee39b /script-beta/vm/eachDef.lua | |
parent | ec0d35bbca1fd3e5bc3725f52b7c2a88cd98b3be (diff) | |
download | lua-language-server-c46e1fd0781750c7d454e7120fe4f6cccce84d8b.zip |
整理代码
Diffstat (limited to 'script-beta/vm/eachDef.lua')
-rw-r--r-- | script-beta/vm/eachDef.lua | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index ec9af0da..db70cecf 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -1,36 +1,48 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' -local function eachDef(source) +local m = {} + +function m.searchDefAcrossRequire(results) + +end + +function m.mergeResults(a, b, mark) + for _, r in ipairs(b) do + if not mark[r] then + mark[r] = true + a[#a+1] = r + end + end + return a +end + +function m.eachDef(source, results, mark) + results = results or {} + mark = mark or {} + if mark[source] then + return results + end + + m.mergeResults(results, guide.requestDefinition(source), mark) + m.searchDefAcrossRequire(results) + local lib = vm.getLibrary(source) - local value = guide.getObjectValue(source) - local results = guide.requestDefinition(source) if lib then results[#results+1] = lib end + + local value = guide.getObjectValue(source) if value then - vm.eachDef(value, function (res) - results[#results+1] = res - end) + m.eachDef(value, results, mark) end + return results end function vm.eachDef(source, callback) - local cache = vm.cache.eachDef[source] - if cache ~= nil then - for i = 1, #cache do - callback(cache[i]) - end - return - end - local unlock = vm.lock('eachDef', source) - if not unlock then - return - end - cache = eachDef(source) or false + local cache = vm.cache.eachDef[source] or m.eachDef(source) vm.cache.eachDef[source] = cache - unlock() for i = 1, #cache do callback(cache[i]) end |