diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-05-30 15:20:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-05-30 15:20:30 +0800 |
commit | 529440f6a2d642d7df47cf4b5d54d9e538761f7a (patch) | |
tree | 78f725d2f2ea3dc8000e6c603f835ef70352d273 /script-beta/vm/eachDef.lua | |
parent | 998540b6ccedb5982a81ee0de73085852795cfd8 (diff) | |
download | lua-language-server-529440f6a2d642d7df47cf4b5d54d9e538761f7a.zip |
整理代码
Diffstat (limited to 'script-beta/vm/eachDef.lua')
-rw-r--r-- | script-beta/vm/eachDef.lua | 27 |
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 |