diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-17 16:45:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-17 16:45:53 +0800 |
commit | e67dd05a15a76d9ee6addb6519fd98e6527d2b09 (patch) | |
tree | 520a569d1a4bb8a3e4e0bbbc219e62bc5ed5a969 /script/vm | |
parent | 844bc87bcb11fade43e06b5e8ac8421f2b0d3630 (diff) | |
download | lua-language-server-e67dd05a15a76d9ee6addb6519fd98e6527d2b09.zip |
stash
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/docs.lua | 51 | ||||
-rw-r--r-- | script/vm/getDocs.lua | 86 | ||||
-rw-r--r-- | script/vm/globals.lua | 51 | ||||
-rw-r--r-- | script/vm/init.lua | 2 |
4 files changed, 23 insertions, 167 deletions
diff --git a/script/vm/docs.lua b/script/vm/docs.lua deleted file mode 100644 index df87d46a..00000000 --- a/script/vm/docs.lua +++ /dev/null @@ -1,51 +0,0 @@ -local files = require 'files' -local noder = require 'core.noder' - -local docsMap = {} -local subscribeMap = {} - -local function popDocs(uri) - if not subscribeMap[uri] then - return - end - for id in pairs(subscribeMap[uri]) do - if docsMap[id] then - docsMap[id][uri] = nil - end - end - subscribeMap[uri] = nil -end - -local function pushDocs(uri) - subscribeMap[uri] = {} - local state = files.getState(uri) - if not state then - return - end - local nodes = noder.compileNodes(state.ast) - for id in pairs(nodes) do - if id:sub(1, 3) == 'dn:' - and noder.getFirstID(id) == id then - if not docsMap[id] then - docsMap[id] = {} - end - docsMap[id][uri] = true - subscribeMap[uri][id] = true - end - end -end - -files.watch(function (ev, uri) - if ev == 'update' then - popDocs(uri) - pushDocs(uri) - end -end) - -local m = {} - -function m.getUrisByID(id) - return docsMap[id] -end - -return m diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index bf99a247..16b82278 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -1,51 +1,32 @@ -local files = require 'files' -local guide = require 'parser.guide' ----@type vm -local vm = require 'vm.vm' -local config = require 'config' -local docs = require 'vm.docs' -local define = require 'proto.define' -local noder = require 'core.noder' - -local function getDocDefinesInAst(results, root, name) - for _, doc in ipairs(root.docs) do - if doc.type == 'doc.class' then - if not name or name == doc.class[1] then - results[#results+1] = doc.class - end - elseif doc.type == 'doc.alias' then - if not name or name == doc.alias[1] then - results[#results+1] = doc.alias - end - end - end -end +local files = require 'files' +local guide = require 'parser.guide' +local vm = require 'vm.vm' +local config = require 'config' +local collector = require 'core.collector' +local define = require 'proto.define' +local noder = require 'core.noder' ---获取class与alias ---@param name? string ---@return parser.guide.object[] function vm.getDocDefines(name) + local cache = vm.getCache 'getDocDefines' + if cache[name] then + return cache[name] + end local results = {} - if name then - local id = 'dn:' .. name - local uris = docs.getUrisByID(id) - if not uris then - return results - end - for uri in pairs(uris) do - local state = files.getState(uri) - if state then - getDocDefinesInAst(results, state.ast, name) - end - end - else - for uri in files.eachFile() do - local state = files.getState(uri) - if state then - getDocDefinesInAst(results, state.ast, name) + local id = 'def:dn:' .. (name or '') + for node in collector.each(id) do + if node.sources then + for _, source in ipairs(node.sources) do + if source.type == 'doc.class.name' + or source.type == 'doc.alias.name' then + results[#results+1] = source + end end end end + cache[name] = results return results end @@ -53,31 +34,10 @@ function vm.isDocDefined(name) if define.BuiltinClass[name] then return true end - local cache = vm.getCache 'isDocDefined' - if cache[name] ~= nil then - return cache[name] - end - local id = 'dn:' .. name - local uris = docs.getUrisByID(id) - if not uris then - cache[name] = false - return - end - for uri in pairs(uris) do - local state = files.getState(uri) - local node = noder.getNodeByID(state.ast, id) - if node and node.sources then - for _, source in ipairs(node.sources) do - local doc = source.parent - if doc.type == 'doc.class' - or doc.type == 'doc.alias' then - cache[name] = true - return true - end - end - end + local id = 'def:dn:' .. name + if collector.has(id) then + return true end - cache[name] = false return false end diff --git a/script/vm/globals.lua b/script/vm/globals.lua deleted file mode 100644 index 3c74f8b0..00000000 --- a/script/vm/globals.lua +++ /dev/null @@ -1,51 +0,0 @@ -local files = require 'files' -local noder = require 'core.noder' - -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 - local nodes = noder.compileNodes(state.ast) - for id in pairs(nodes) do - if id:sub(1, 2) == 'g:' - and noder.getFirstID(id) == id then - if not globalsMap[id] then - globalsMap[id] = {} - end - globalsMap[id][uri] = true - subscribeMap[uri][id] = true - end - end -end - -files.watch(function (ev, uri) - if ev == 'update' then - popGlobals(uri) - pushGlobals(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 705a7117..c38f01d5 100644 --- a/script/vm/init.lua +++ b/script/vm/init.lua @@ -6,6 +6,4 @@ require 'vm.eachDef' require 'vm.eachRef' require 'vm.getLinks' require 'vm.guideInterface' -require 'vm.globals' -require 'vm.docs' return vm |