summaryrefslogtreecommitdiff
path: root/script/vm/eachRef.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/eachRef.lua')
-rw-r--r--script/vm/eachRef.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/script/vm/eachRef.lua b/script/vm/eachRef.lua
new file mode 100644
index 00000000..4e735abf
--- /dev/null
+++ b/script/vm/eachRef.lua
@@ -0,0 +1,39 @@
+local vm = require 'vm.vm'
+local guide = require 'parser.guide'
+local util = require 'utility'
+local await = require 'await'
+
+local function getRefs(source, deep)
+ local results = {}
+ local lock = vm.lock('eachRef', source)
+ if not lock then
+ return results
+ end
+
+ await.delay()
+
+ local clock = os.clock()
+ local myResults, count = guide.requestReference(source, vm.interface, deep)
+ if DEVELOP and os.clock() - clock > 0.1 then
+ log.warn('requestReference', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))
+ end
+ vm.mergeResults(results, myResults)
+
+ lock()
+
+ return results
+end
+
+function vm.getRefs(source, deep)
+ if guide.isGlobal(source) then
+ local key = guide.getKeyName(source)
+ return vm.getGlobals(key)
+ else
+ local cache = vm.getCache('eachRef')[source]
+ or getRefs(source, deep)
+ if deep then
+ vm.getCache('eachRef')[source] = cache
+ end
+ return cache
+ end
+end