diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-07-25 15:01:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-07-25 15:01:34 +0800 |
commit | 123f9d3647c464a6a38cbf90e5accf39c8fb40ba (patch) | |
tree | 491059fa03a102a82999afd47defa290396394f8 | |
parent | 1e11d151c29b1e107c09ef694ed9fe2d929b6fc9 (diff) | |
download | lua-language-server-123f9d3647c464a6a38cbf90e5accf39c8fb40ba.zip |
解耦
-rw-r--r-- | script-beta/files.lua | 8 | ||||
-rw-r--r-- | script-beta/vm/eachDef.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/eachField.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/eachRef.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/getGlobals.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/getLibrary.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/getValue.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/vm.lua | 31 |
8 files changed, 27 insertions, 36 deletions
diff --git a/script-beta/files.lua b/script-beta/files.lua index be890bb0..bbcabb0f 100644 --- a/script-beta/files.lua +++ b/script-beta/files.lua @@ -3,8 +3,6 @@ local config = require 'config' local glob = require 'glob' local furi = require 'file-uri' local parser = require 'parser' -local vm = require 'vm.vm' -local guide = require 'parser.guide' local proto = require 'proto' local lang = require 'language' @@ -75,10 +73,6 @@ function m.setText(uri, text) file.lines = nil file.cache = {} m.globalVersion = m.globalVersion + 1 - if not m.needRefreshUri then - m.needRefreshUri = {} - end - m.needRefreshUri[file] = true end --- 监听编译完成 @@ -123,7 +117,6 @@ function m.remove(uri) m.fileMap[uri] = nil m.globalVersion = m.globalVersion + 1 - vm.refreshCache() end --- 移除所有文件 @@ -133,7 +126,6 @@ function m.removeAll() end m.globalVersion = m.globalVersion + 1 m.notifyCache = {} - vm.refreshCache() end --- 遍历文件 diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index ad844759..fd34bed3 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -34,8 +34,8 @@ function m.eachDef(source, results) end function vm.getDefs(source) - local cache = vm.cache.eachDef[source] or m.eachDef(source) - vm.cache.eachDef[source] = cache + local cache = vm.getCache('eachDef')[source] or m.eachDef(source) + vm.getCache('eachDef')[source] = cache return cache end diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua index bd6e7db9..9374865d 100644 --- a/script-beta/vm/eachField.lua +++ b/script-beta/vm/eachField.lua @@ -36,7 +36,7 @@ local function eachField(source) end function vm.eachField(source, callback) - local cache = vm.cache.eachField[source] + local cache = vm.getCache('eachField')[source] if cache ~= nil then for i = 1, #cache do callback(cache[i]) @@ -48,7 +48,7 @@ function vm.eachField(source, callback) return end cache = eachField(source) or false - vm.cache.eachField[source] = cache + vm.getCache('eachField')[source] = cache unlock() for i = 1, #cache do callback(cache[i]) diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua index 8df63022..270a6875 100644 --- a/script-beta/vm/eachRef.lua +++ b/script-beta/vm/eachRef.lua @@ -17,8 +17,8 @@ local function eachRef(source, results) end function vm.getRefs(source) - local cache = vm.cache.eachRef[source] or eachRef(source) - vm.cache.eachDef[source] = cache + local cache = vm.getCache('eachRef')[source] or eachRef(source) + vm.getCache('eachDef')[source] = cache return cache end diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua index 8ac63090..adc6c9fc 100644 --- a/script-beta/vm/getGlobals.lua +++ b/script-beta/vm/getGlobals.lua @@ -35,11 +35,11 @@ local function getGlobals(name) end function vm.getGlobals(name) - local cache = vm.cache.getGlobals[name] + local cache = vm.getCache('getGlobals')[name] if cache ~= nil then return cache end cache = getGlobals(name) - vm.cache.getGlobals[name] = cache + vm.getCache('getGlobals')[name] = cache return cache end diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua index 395a5b74..34047805 100644 --- a/script-beta/vm/getLibrary.lua +++ b/script-beta/vm/getLibrary.lua @@ -97,7 +97,7 @@ local function getLibrary(source) end function vm.getLibrary(source) - local cache = vm.cache.getLibrary[source] + local cache = vm.getCache('getLibrary')[source] if cache ~= nil then return cache end @@ -106,7 +106,7 @@ function vm.getLibrary(source) return end cache = getLibrary(source) or false - vm.cache.getLibrary[source] = cache + vm.getCache('getLibrary')[source] = cache unlock() return cache end diff --git a/script-beta/vm/getValue.lua b/script-beta/vm/getValue.lua index d5665a8c..806a0c44 100644 --- a/script-beta/vm/getValue.lua +++ b/script-beta/vm/getValue.lua @@ -1017,7 +1017,7 @@ function vm.getValue(source) if not source then return end - local cache = vm.cache.getValue[source] + local cache = vm.getCache('getValue')[source] if cache ~= nil then return cache end @@ -1026,7 +1026,7 @@ function vm.getValue(source) return end cache = getValue(source) or false - vm.cache.getValue[source] = cache + vm.getCache('getValue')[source] = cache unlock() return cache end diff --git a/script-beta/vm/vm.lua b/script-beta/vm/vm.lua index 21c37556..85df007f 100644 --- a/script-beta/vm/vm.lua +++ b/script-beta/vm/vm.lua @@ -1,5 +1,6 @@ local guide = require 'parser.guide' local util = require 'utility' +local files = require 'files' local setmetatable = setmetatable local assert = assert @@ -142,22 +143,20 @@ end m.cacheTracker = setmetatable({}, { __mode = 'kv' }) ---- 刷新缓存 -function m.refreshCache() - if m.cache then - m.cache.dead = true - end - m.cache = { - eachRef = {}, - eachDef = {}, - eachField = {}, - eachMeta = {}, - getLibrary = {}, - getValue = {}, - getGlobals = {}, - } - m.locked = setmetatable({}, { __mode = 'k' }) - m.cacheTracker[m.cache] = true +function m.getCache(name) + if m.cacheVersion ~= files.globalVersion then + if m.cache then + m.cache.dead = true + end + m.cacheVersion = files.globalVersion + m.cache = {} + m.locked = setmetatable({}, { __mode = 'k' }) + m.cacheTracker[m.cache] = true + end + if not m.cache[name] then + m.cache[name] = {} + end + return m.cache[name] end return m |