summaryrefslogtreecommitdiff
path: root/script-beta/vm/eachDef.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-05-30 15:20:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-05-30 15:20:30 +0800
commit529440f6a2d642d7df47cf4b5d54d9e538761f7a (patch)
tree78f725d2f2ea3dc8000e6c603f835ef70352d273 /script-beta/vm/eachDef.lua
parent998540b6ccedb5982a81ee0de73085852795cfd8 (diff)
downloadlua-language-server-529440f6a2d642d7df47cf4b5d54d9e538761f7a.zip
整理代码
Diffstat (limited to 'script-beta/vm/eachDef.lua')
-rw-r--r--script-beta/vm/eachDef.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
new file mode 100644
index 00000000..75c29526
--- /dev/null
+++ b/script-beta/vm/eachDef.lua
@@ -0,0 +1,27 @@
+local vm = require 'vm.vm'
+local guide = require 'parser.guide'
+
+local function eachDef(source)
+ local results = guide.requestDefinition(source)
+ 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
+ vm.cache.eachDef[source] = cache
+ unlock()
+ for i = 1, #cache do
+ callback(cache[i])
+ end
+end