diff options
Diffstat (limited to 'script/cli')
-rw-r--r-- | script/cli/doc.lua | 63 | ||||
-rw-r--r-- | script/cli/doc2md.lua | 30 |
2 files changed, 77 insertions, 16 deletions
diff --git a/script/cli/doc.lua b/script/cli/doc.lua index d07375e4..ae821527 100644 --- a/script/cli/doc.lua +++ b/script/cli/doc.lua @@ -100,12 +100,13 @@ end ---@async ---@param global vm.global ---@param results table -local function collect(global, results) +local function collectTypes(global, results) if guide.isBasicType(global.name) then return end local result = { name = global.name, + type = 'type', desc = nil, defines = {}, fields = {}, @@ -207,6 +208,48 @@ local function collect(global, results) end ---@async +---@param global vm.global +---@param results table +local function collectVars(global, results) + local result = { + name = global:getCodeName(), + type = 'variable', + desc = nil, + defines = {}, + } + for _, set in ipairs(global:getSets(ws.rootUri)) do + local uri = guide.getUri(set) + if files.isLibrary(uri) then + goto CONTINUE + end + if set.type == 'setglobal' + or set.type == 'setfield' + or set.type == 'setmethod' + or set.type == 'setindex' then + result.defines[#result.defines+1] = { + type = set.type, + file = guide.getUri(set), + start = set.start, + finish = set.finish, + extends = packObject(set.value), + } + result.desc = result.desc or getDesc(set) + end + ::CONTINUE:: + end + if #result.defines == 0 then + return + end + table.sort(result.defines, function (a, b) + if a.file ~= b.file then + return a.file < b.file + end + return a.start < b.start + end) + results[#results+1] = result +end + +---@async ---@param outputPath string function export.makeDoc(outputPath) local results = {} @@ -222,15 +265,23 @@ function export.makeDoc(outputPath) await.sleep(0.1) local prog <close> = progress.create(ws.rootUri, '正在生成文档...', 0) - local globals = vm.getGlobals 'type' + local globalTypes = vm.getGlobals 'type' + local globalVars = vm.getGlobals 'variable' - local max = #globals - for i, global in ipairs(globals) do - collect(global, results) + local max = #globalTypes + #globalVars + + for i, global in ipairs(globalTypes) do + collectTypes(global, results) prog:setMessage(('%d/%d'):format(i, max)) prog:setPercentage(i / max * 100) end + for i, global in ipairs(globalVars) do + collectVars(global, results) + prog:setMessage(('%d/%d'):format(i + #globalTypes, max)) + prog:setPercentage((i + #globalTypes) / max * 100) + end + table.sort(results, function (a, b) return a.name < b.name end) @@ -284,7 +335,7 @@ function export.runCLI() local max = #globals for i, global in ipairs(globals) do - collect(global, results) + collectTypes(global, results) if os.clock() - lastClock > 0.2 then lastClock = os.clock() local output = '\x0D' diff --git a/script/cli/doc2md.lua b/script/cli/doc2md.lua index 9cc6c385..70c1b2a0 100644 --- a/script/cli/doc2md.lua +++ b/script/cli/doc2md.lua @@ -18,16 +18,26 @@ function export.buildMD(outputPath) md:emptyLine() md:add('md', class.desc) md:emptyLine() - local mark = {} - for _, field in ipairs(class.fields) do - if not mark[field.name] then - mark[field.name] = true - md:add('md', '## ' .. field.name) - md:emptyLine() - md:add('lua', field.extends.view) - md:emptyLine() - md:add('md', field.desc) - md:emptyLine() + if class.defines then + for _, define in ipairs(class.defines) do + if define.extends then + md:add('lua', define.extends.view) + md:emptyLine() + end + end + end + if class.fields then + local mark = {} + for _, field in ipairs(class.fields) do + if not mark[field.name] then + mark[field.name] = true + md:add('md', '## ' .. field.name) + md:emptyLine() + md:add('lua', field.extends.view) + md:emptyLine() + md:add('md', field.desc) + md:emptyLine() + end end end md:splitLine() |