diff options
Diffstat (limited to 'script/vm/getDocs.lua')
-rw-r--r-- | script/vm/getDocs.lua | 155 |
1 files changed, 29 insertions, 126 deletions
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index cfa9326f..dbb8b4fd 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -1,148 +1,51 @@ -local files = require 'files' -local util = require 'utility' -local guide = require 'core.guide' +local files = require 'files' +local guide = require 'parser.guide' ---@type vm -local vm = require 'vm.vm' -local config = require 'config' +local vm = require 'vm.vm' +local config = require 'config' +local searcher = require 'core.searcher' -local function getTypesOfFile(uri) - local types = {} - local ast = files.getAst(uri) - if not ast or not ast.ast.docs then - return types - end - guide.eachSource(ast.ast.docs, function (src) - if src.type == 'doc.type.name' - or src.type == 'doc.class.name' - or src.type == 'doc.extends.name' - or src.type == 'doc.alias.name' then - if src.type == 'doc.type.name' then - if guide.getParentDocTypeTable(src) then - return - end +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 - local name = src[1] - if name then - if not types[name] then - types[name] = {} - end - types[name][#types[name]+1] = src + elseif doc.type == 'doc.alias' then + if not name or name == doc.alias[1] then + results[#results+1] = doc.alias end end - end) - return types + end end -local function getDocTypes(name) +---获取class与alias +---@param name? string +---@return parser.guide.object[] +function vm.getDocDefines(name) local results = {} - if name == 'any' - or name == 'nil' then - return results - end for uri in files.eachFile() do - local cache = files.getCache(uri) - cache.classes = cache.classes or getTypesOfFile(uri) - if name == '*' then - for _, sources in util.sortPairs(cache.classes) do - for _, source in ipairs(sources) do - results[#results+1] = source - end - end - else - if cache.classes[name] then - for _, source in ipairs(cache.classes[name]) do - results[#results+1] = source - end - end - end + local ast = files.getAst(uri) + getDocDefinesInAst(results, ast.ast, name) end return results end -function vm.getDocEnums(doc, mark, results) +function vm.getDocEnums(doc) if not doc then return nil end - mark = mark or {} - if mark[doc] then - return nil - end - mark[doc] = true - results = results or {} - for _, enum in ipairs(doc.enums) do - results[#results+1] = enum - end - for _, resume in ipairs(doc.resumes) do - results[#results+1] = resume - end - for _, unit in ipairs(doc.types) do - if unit.type == 'doc.type.name' then - for _, other in ipairs(vm.getDocTypes(unit[1])) do - if other.type == 'doc.alias.name' then - vm.getDocEnums(other.parent.extends, mark, results) - end - end - end - end - return results -end + local defs = searcher.requestDefinition(doc) + local results = {} -function vm.getDocTypeUnits(doc, mark, results) - if not doc then - return nil - end - mark = mark or {} - if mark[doc] then - return nil - end - mark[doc] = true - results = results or {} - for _, enum in ipairs(doc.enums) do - results[#results+1] = enum - end - for _, resume in ipairs(doc.resumes) do - results[#results+1] = resume - end - for _, unit in ipairs(doc.types) do - if unit.type == 'doc.type.name' then - for _, other in ipairs(vm.getDocTypes(unit[1])) do - if other.type == 'doc.alias.name' then - vm.getDocTypeUnits(other.parent.extends, mark, results) - elseif other.type == 'doc.class.name' then - results[#results+1] = other - end - end - else - results[#results+1] = unit + for _, def in ipairs(defs) do + if def.type == 'doc.type.enum' + or def.type == 'doc.resume' then + results[#results+1] = def end end - return results -end - -function vm.getDocTypes(name) - local cache = vm.getCache('getDocTypes')[name] - if cache ~= nil then - return cache - end - cache = getDocTypes(name) - vm.getCache('getDocTypes')[name] = cache - return cache -end -function vm.getDocClass(name) - local cache = vm.getCache('getDocClass')[name] - if cache ~= nil then - return cache - end - cache = {} - local results = getDocTypes(name) - for _, doc in ipairs(results) do - if doc.type == 'doc.class.name' then - cache[#cache+1] = doc - end - end - vm.getCache('getDocClass')[name] = cache - return cache + return results end function vm.isMetaFile(uri) @@ -224,7 +127,7 @@ end function vm.isDeprecated(value, deep) if deep then - local defs = vm.getDefs(value, 0) + local defs = vm.getDefs(value) if #defs == 0 then return false end |