diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-18 19:27:44 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-18 19:27:44 +0800 |
commit | 1d512d14481843c20a0760af6f2f19c6ad497861 (patch) | |
tree | 50bb8be23d3866abfde89c50e1332a03a2ec1d25 /script-beta/parser | |
parent | ebe404b5f861f251722144f260f364cd0b3b2981 (diff) | |
download | lua-language-server-1d512d14481843c20a0760af6f2f19c6ad497861.zip |
只有第一层的cache为全局共享
Diffstat (limited to 'script-beta/parser')
-rw-r--r-- | script-beta/parser/guide.lua | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 95ed6d17..c766a977 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1879,16 +1879,49 @@ function m.cleanResults(results) end end +--function m.getRefCache(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, status.index == 1) +-- else +-- return status.interface.cache(obj, mode, status.index == 1) +-- end +--end + function m.getRefCache(status, obj, mode) - if not status.interface.cache then - return + local cache, globalCache + if status.index == 1 then + globalCache = status.interface.cache and status.interface.cache() or {} end + cache = status.cache.refCache or {} + status.cache.refCache = cache 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) + obj = m.getKeyName(obj) + end + if not cache[mode] then + cache[mode] = {} + end + if globalCache and not globalCache[mode] then + globalCache[mode] = {} + end + local sourceCache = globalCache and globalCache[mode][obj] or cache[mode][obj] + if sourceCache then + return sourceCache + end + sourceCache = {} + cache[mode][obj] = sourceCache + if globalCache then + globalCache[mode][obj] = sourceCache + end + return nil, function (results) + for i = 1, #results do + sourceCache[i] = results[i] + end end end @@ -2825,10 +2858,7 @@ function m.searchInfer(status, obj) obj = obj.parent end - local cache, makeCache - if status.interface.cache then - cache, makeCache = status.interface.cache(obj, 'infer') - end + local cache, makeCache = m.getRefCache(status, obj, 'infer') if cache then for i = 1, #cache do status.results[#status.results+1] = cache[i] |