summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-16 00:09:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-16 00:09:54 +0800
commit51592cb52f944d8b22ce0a7e1ac1a940a4aef735 (patch)
tree20d6a02fe7ecc5d2d0b239afd702e488d84920a9 /script-beta
parent643bdff2713f8d0ac0b9bfd781e35fa2246a1c6d (diff)
downloadlua-language-server-51592cb52f944d8b22ce0a7e1ac1a940a4aef735.zip
从业务层获取缓存
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/parser/guide.lua25
-rw-r--r--script-beta/vm/eachField.lua2
-rw-r--r--script-beta/vm/guideInterface.lua18
3 files changed, 44 insertions, 1 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 55aa339a..faa77745 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -1736,9 +1736,30 @@ function m.cleanResults(results)
end
end
+function m.getCache(status, obj, mode)
+ if not status.interface.cache then
+ return
+ end
+ if obj.type == 'getglobal'
+ or obj.type == 'setglobal' then
+ local name = m.getKeyName(obj)
+ return status.interface.cache(name, mode)
+ else
+ return status.interface.cache(obj, mode)
+ end
+end
+
function m.searchRefs(status, obj, mode)
status.depth = status.depth + 1
+ local cache, makeCache = m.getCache(status, obj, mode)
+ if cache then
+ for i = 1, #cache do
+ status.results[#status.results+1] = cache[i]
+ end
+ return
+ end
+
-- 检查单步引用
local res = m.getStepRef(obj, mode)
if res then
@@ -1759,6 +1780,10 @@ function m.searchRefs(status, obj, mode)
status.depth = status.depth - 1
m.cleanResults(status.results)
+
+ if makeCache then
+ makeCache(status.results)
+ end
end
function m.searchRefOfValue(status, obj)
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index 7dab51e7..ffc16228 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -50,7 +50,7 @@ function vm.eachField(source, callback)
if not unlock then
return
end
- cache = eachField(source) or false
+ cache = eachField(source)
vm.getCache('eachField')[source] = cache
unlock()
for i = 1, #cache do
diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua
index 748530e9..96e553be 100644
--- a/script-beta/vm/guideInterface.lua
+++ b/script-beta/vm/guideInterface.lua
@@ -82,3 +82,21 @@ function vm.interface.link(uri)
await.delay()
return vm.getLinksTo(uri)
end
+
+function vm.interface.cache(source, mode)
+ local cache = vm.getCache('cache')
+ if not cache[mode] then
+ cache[mode] = {}
+ end
+ local sourceCache = cache[mode][source]
+ if cache[mode][source] then
+ return sourceCache
+ end
+ sourceCache = {}
+ cache[mode][source] = sourceCache
+ return nil, function (results)
+ for i = 1, #results do
+ sourceCache[i] = results[i]
+ end
+ end
+end