summaryrefslogtreecommitdiff
path: root/script-beta/vm
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
parent998540b6ccedb5982a81ee0de73085852795cfd8 (diff)
downloadlua-language-server-529440f6a2d642d7df47cf4b5d54d9e538761f7a.zip
整理代码
Diffstat (limited to 'script-beta/vm')
-rw-r--r--script-beta/vm/eachDef.lua27
-rw-r--r--script-beta/vm/eachRef.lua27
-rw-r--r--script-beta/vm/init.lua2
-rw-r--r--script-beta/vm/vm.lua14
4 files changed, 56 insertions, 14 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
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
new file mode 100644
index 00000000..c5d3c845
--- /dev/null
+++ b/script-beta/vm/eachRef.lua
@@ -0,0 +1,27 @@
+local vm = require 'vm.vm'
+local guide = require 'parser.guide'
+
+local function eachRef(source)
+ local results = guide.requestReference(source)
+ return results
+end
+
+function vm.eachRef(source, callback)
+ local cache = vm.cache.eachRef[source]
+ if cache ~= nil then
+ for i = 1, #cache do
+ callback(cache[i])
+ end
+ return
+ end
+ local unlock = vm.lock('eachRef', source)
+ if not unlock then
+ return
+ end
+ cache = eachRef(source) or false
+ vm.cache.eachRef[source] = cache
+ unlock()
+ for i = 1, #cache do
+ callback(cache[i])
+ end
+end
diff --git a/script-beta/vm/init.lua b/script-beta/vm/init.lua
index be120fbf..8cc7ae92 100644
--- a/script-beta/vm/init.lua
+++ b/script-beta/vm/init.lua
@@ -7,4 +7,6 @@ require 'vm.getValue'
require 'vm.getClass'
require 'vm.getMeta'
require 'vm.eachField'
+require 'vm.eachDef'
+require 'vm.eachRef'
return vm
diff --git a/script-beta/vm/vm.lua b/script-beta/vm/vm.lua
index ff5c1fe3..556de3df 100644
--- a/script-beta/vm/vm.lua
+++ b/script-beta/vm/vm.lua
@@ -136,20 +136,6 @@ function m.getKeyName(source)
return guide.getKeyName(source)
end
-function m.eachDef(source, callback)
- local results = guide.requestDefinition(source)
- for i = 1, #results do
- callback(results[i])
- end
-end
-
-function m.eachRef(source, callback)
- local results = guide.requestReference(source)
- for i = 1, #results do
- callback(results[i])
- end
-end
-
m.cacheTracker = setmetatable({}, { __mode = 'kv' })
--- 刷新缓存