diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-08-02 22:13:36 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-08-02 22:13:36 +0800 |
commit | a6a37500fb306d5aaf14306f5aa7d00f86483133 (patch) | |
tree | aff25d3e025fd2ddccac9e0eb7610c9c9ab378d9 /script/core/searcher.lua | |
parent | 2ddf4cd749b3fcbaba8123d074a790b4868fa1e1 (diff) | |
download | lua-language-server-a6a37500fb306d5aaf14306f5aa7d00f86483133.zip |
add cache
Diffstat (limited to 'script/core/searcher.lua')
-rw-r--r-- | script/core/searcher.lua | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 777da050..b246094c 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -284,8 +284,15 @@ local function checkCache(status, uri, expect, mode) end return true end - fileCache[expect] = status.results - return false + return false, function () + fileCache[expect] = status.results + if mode == 'def' then + return + end + for id in pairs(status.ids) do + fileCache[id] = status.results + end + end end local function stop(status, msg) @@ -387,6 +394,13 @@ function m.searchRefsByID(status, uri, expect, mode) status.elock[uri] = elock local function search(id, field) + if not field then + local cached = checkCache(status, uri, id, mode) + if cached then + return + end + status.ids[id] = true + end local firstID = noder.getFirstID(id) if ignoredIDs[firstID] and (field or firstID ~= id) then return @@ -1019,7 +1033,9 @@ function m.searchRefs(status, source, mode) return end - if checkCache(status, uri, id, mode) then + local cached, makeCache = checkCache(status, uri, id, mode) + + if cached then return end @@ -1027,6 +1043,7 @@ function m.searchRefs(status, source, mode) log.debug('searchRefs:', id) end m.searchRefsByID(status, uri, id, mode) + makeCache() end ---搜索对象的field @@ -1044,12 +1061,15 @@ function m.searchFields(status, source, mode, field) end if field == '*' then if source.special == '_G' then - if checkCache(status, uri, '*', mode) then + local cached, makeCache = checkCache(status, uri, '*', mode) + if cached then return end searchAllGlobals(status, mode) + makeCache() else - if checkCache(status, uri, id .. '*', mode) then + local cached, makeCache = checkCache(status, uri, id .. '*', mode) + if cached then return end local newStatus = m.status('field') @@ -1057,6 +1077,7 @@ function m.searchFields(status, source, mode, field) for _, def in ipairs(newStatus.results) do getField(status, def, mode) end + makeCache() end else if source.special == '_G' then @@ -1066,10 +1087,12 @@ function m.searchFields(status, source, mode, field) else fullID = sformat('%s%s%s', 'g:', '', field) end - if checkCache(status, uri, fullID, mode) then + local cahced, makeCache = checkCache(status, uri, fullID, mode) + if cahced then return end m.searchRefsByID(status, uri, fullID, mode) + makeCache() else local fullID if type(field) == 'string' then @@ -1077,10 +1100,12 @@ function m.searchFields(status, source, mode, field) else fullID = sformat('%s%s%s', id, noder.SPLIT_CHAR, field) end - if checkCache(status, uri, fullID, mode) then + local cahced, makeCache = checkCache(status, uri, fullID, mode) + if cahced then return end m.searchRefsByID(status, uri, fullID, mode) + makeCache() end end end @@ -1106,11 +1131,12 @@ function m.status(mode) smark = {}, footprint = {}, count = 0, + ids = {}, ftag = {}, btag = {}, dontCross = 0, mode = mode, - cache = vm.getCache('searcher:' .. mode) + cache = vm.getCache('searcher:' .. mode), } return status end |