diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-11 15:15:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-11 15:15:19 +0800 |
commit | e6f1dd06dbe5c70a8f8b239b73bb3e4a8caf7554 (patch) | |
tree | c119babd91098f761e54940ae016d533d363ade4 | |
parent | 50e6cd02d535e12e085eab7d8bdcb4757be857f2 (diff) | |
download | lua-language-server-e6f1dd06dbe5c70a8f8b239b73bb3e4a8caf7554.zip |
global cache
-rw-r--r-- | script/core/searcher.lua | 27 | ||||
-rw-r--r-- | script/vm/getGlobals.lua (renamed from script/vm/getGlobals.lua.txt) | 0 | ||||
-rw-r--r-- | script/vm/globals.lua | 35 | ||||
-rw-r--r-- | script/vm/init.lua | 1 |
4 files changed, 54 insertions, 9 deletions
diff --git a/script/core/searcher.lua b/script/core/searcher.lua index fc19fc80..095ff782 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -5,6 +5,7 @@ local generic = require 'core.generic' local ws = require 'workspace' local vm = require 'vm.vm' local await = require 'await' +local globals = require 'vm.globals' local NONE = {'NONE'} local LAST = {'LAST'} @@ -424,8 +425,12 @@ function m.searchRefsByID(status, uri, expect, mode) return end status.crossed[firstID] = true + local uris = globals.getUrisByID(firstID) + if not uris then + return + end local tid = id .. (field or '') - for guri in files.eachFile() do + for guri in pairs(uris) do if not files.eq(uri, guri) then crossSearch(status, guri, tid, mode) end @@ -614,10 +619,28 @@ local function searchAllGlobalByUri(status, mode, uri, fullID) end end -local function searchAllGlobals(status, mode, fullID) +local function searchAllGlobals(status, mode) for uri in files.eachFile() do + searchAllGlobalByUri(status, mode, uri) + end +end + +---查找全局变量 +---@param uri uri +---@param mode guide.searchmode +---@param name string +---@return parser.guide.object[] +function m.findGlobals(uri, mode, name) + local status = m.status(mode) + + if name then + local fullID = ('g:%q'):format(name) searchAllGlobalByUri(status, mode, uri, fullID) + else + searchAllGlobalByUri(status, mode, uri) end + + return status.results end ---搜索对象的引用 diff --git a/script/vm/getGlobals.lua.txt b/script/vm/getGlobals.lua index e5bcafc0..e5bcafc0 100644 --- a/script/vm/getGlobals.lua.txt +++ b/script/vm/getGlobals.lua diff --git a/script/vm/globals.lua b/script/vm/globals.lua index cf18aa19..7a0eeb59 100644 --- a/script/vm/globals.lua +++ b/script/vm/globals.lua @@ -2,24 +2,39 @@ local files = require 'files' local await = require 'await' local noder = require 'core.noder' -local globalsMap = {} -local subscribe = {} +local globalsMap = {} +local subscribeMap = {} local function popGlobals(uri) - + if not subscribeMap[uri] then + return + end + for id in pairs(subscribeMap[uri]) do + if globalsMap[id] then + globalsMap[id][uri] = nil + end + end + subscribeMap[uri] = nil end local function pushGlobals(uri) + subscribeMap[uri] = {} local state = files.getState(uri) if not state then return end - noder.compileNodes(state.ast) - + local nodes = noder.compileNodes(state.ast) + for id in pairs(nodes) do + if id:sub(1, 2) == 'g:' then + if not globalsMap[id] then + globalsMap[id] = {} + end + globalsMap[id][uri] = true + subscribeMap[uri][id] = true + end + end end -local m = {} - files.watch(function (ev, uri) if ev == 'update' then popGlobals(uri) @@ -28,4 +43,10 @@ files.watch(function (ev, uri) end end) +local m = {} + +function m.getUrisByID(id) + return globalsMap[id] +end + return m diff --git a/script/vm/init.lua b/script/vm/init.lua index c38f01d5..25ec91f9 100644 --- a/script/vm/init.lua +++ b/script/vm/init.lua @@ -6,4 +6,5 @@ require 'vm.eachDef' require 'vm.eachRef' require 'vm.getLinks' require 'vm.guideInterface' +require 'vm.globals' return vm |