diff options
-rw-r--r-- | script/core/searcher.lua | 57 | ||||
-rw-r--r-- | script/files.lua | 4 |
2 files changed, 47 insertions, 14 deletions
diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 7e8d47b1..777da050 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -340,6 +340,34 @@ local function isCallID(field) return false end +local genercCache = { + mark = {}, + genericCallArgs = {}, + closureCache = {}, +} + +local function flushGeneric() + --清除来自泛型的临时对象 + for _, closure in pairs(genercCache.closureCache) do + local noders = noder.getNoders(closure) + noder.removeID(noders, noder.getID(closure)) + if closure then + for _, value in ipairs(closure.values) do + noder.removeID(noders, noder.getID(value)) + end + end + end + genercCache.mark = {} + genercCache.closureCache = {} + genercCache.genericCallArgs = {} +end + +files.watch(function (ev) + if ev == 'version' then + flushGeneric() + end +end) + function m.searchRefsByID(status, uri, expect, mode) local ast = files.getState(uri) if not ast then @@ -420,8 +448,8 @@ function m.searchRefsByID(status, uri, expect, mode) return nil end - local genericCallArgs = {} - local closureCache = {} + local genericCallArgs = genercCache.genericCallArgs + local closureCache = genercCache.closureCache local function checkGeneric(source, field) if not source.isGeneric then return @@ -433,6 +461,14 @@ function m.searchRefsByID(status, uri, expect, mode) if not call then return end + local id = genercCache.mark[call] + if id == false then + return + end + if id then + searchID(id, field) + return + end if call.args then for _, arg in ipairs(call.args) do @@ -440,19 +476,22 @@ function m.searchRefsByID(status, uri, expect, mode) end end - local cacheID = noder.getID(source) .. noder.getID(call) + local cacheID = uri .. noder.getID(source) .. noder.getID(call) local closure = closureCache[cacheID] if closure == false then + genercCache.mark[call] = false return end if not closure then closure = generic.createClosure(source, call) closureCache[cacheID] = closure or false if not closure then + genercCache.mark[call] = false return end end - local id = noder.getID(closure) + id = noder.getID(closure) + genercCache.mark[call] = id searchID(id, field) end @@ -861,16 +900,6 @@ function m.searchRefsByID(status, uri, expect, mode) end search(expect) - - --清除来自泛型的临时对象 - for _, closure in pairs(closureCache) do - noder.removeID(noders, noder.getID(closure)) - if closure then - for _, value in ipairs(closure.values) do - noder.removeID(noders, noder.getID(value)) - end - end - end end local function prepareSearch(source) diff --git a/script/files.lua b/script/files.lua index a497577a..e67ab653 100644 --- a/script/files.lua +++ b/script/files.lua @@ -200,6 +200,7 @@ function m.setText(uri, text, isTrust, instance) file.version = file.version + 1 m.globalVersion = m.globalVersion + 1 await.close('files.version') + m.onWatch('version') if create then m.onWatch('create', originUri) end @@ -371,6 +372,7 @@ function m.remove(uri) m.globalVersion = m.globalVersion + 1 await.close('files.version') + m.onWatch('version') m.onWatch('remove', originUri) end @@ -379,6 +381,7 @@ function m.removeAll() local ws = require 'workspace.workspace' m.globalVersion = m.globalVersion + 1 await.close('files.version') + m.onWatch('version') m._pairsCache = nil for uri in pairs(m.fileMap) do if not m.libraryMap[uri] then @@ -397,6 +400,7 @@ end function m.removeAllClosed() m.globalVersion = m.globalVersion + 1 await.close('files.version') + m.onWatch('version') m._pairsCache = nil for uri in pairs(m.fileMap) do if not m.openMap[uri] |