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 /script/vm | |
parent | 50e6cd02d535e12e085eab7d8bdcb4757be857f2 (diff) | |
download | lua-language-server-e6f1dd06dbe5c70a8f8b239b73bb3e4a8caf7554.zip |
global cache
Diffstat (limited to 'script/vm')
-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 |
3 files changed, 29 insertions, 7 deletions
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 |