summaryrefslogtreecommitdiff
path: root/script/vm/getDocs.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/getDocs.lua')
-rw-r--r--script/vm/getDocs.lua86
1 files changed, 23 insertions, 63 deletions
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