local vm = require 'vm.vm' local guide = require 'parser.guide' local files = require 'files' local util = require 'utility' local await = require 'await' local m = {} function m.eachDef(source, simple) local results = {} local lock = vm.lock('eachDef', source) if not lock then return results end await.delay() local clock = os.clock() local myResults, count = guide.requestDefinition(source, vm.interface, simple) if DEVELOP and os.clock() - clock > 0.1 then log.warn('requestDefinition', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })) end vm.mergeResults(results, myResults) lock() return results end function vm.getDefs(source, simple) if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachDefOfGlobal')[name] or vm.getCache('eachDef')[source] or m.eachDef(source) vm.getCache('eachDefOfGlobal')[name] = cache return cache elseif simple then return m.eachDef(source, simple) else local cache = vm.getCache('eachDef')[source] or m.eachDef(source) vm.getCache('eachDef')[source] = cache return cache end end function vm.eachDef(source, callback) local results = vm.getDefs(source) for i = 1, #results do callback(results[i]) end end