diff options
Diffstat (limited to 'script/cli/doc.lua')
-rw-r--r-- | script/cli/doc.lua | 93 |
1 files changed, 42 insertions, 51 deletions
diff --git a/script/cli/doc.lua b/script/cli/doc.lua index ae821527..f94a2066 100644 --- a/script/cli/doc.lua +++ b/script/cli/doc.lua @@ -218,10 +218,6 @@ local function collectVars(global, results) 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' @@ -235,7 +231,6 @@ local function collectVars(global, results) } result.desc = result.desc or getDesc(set) end - ::CONTINUE:: end if #result.defines == 0 then return @@ -250,10 +245,41 @@ local function collectVars(global, results) end ---@async ----@param outputPath string -function export.makeDoc(outputPath) +---@param callback fun(i, max) +function export.export(outputPath, callback) local results = {} + local globals = vm.getAllGlobals() + local max = 0 + for _ in pairs(globals) do + max = max + 1 + end + local i = 0 + for _, global in pairs(globals) do + if global.cate == 'variable' then + collectVars(global, results) + elseif global.cate == 'type' then + collectTypes(global, results) + end + i = i + 1 + callback(i, max) + end + + table.sort(results, function (a, b) + return a.name < b.name + end) + + local docPath = outputPath .. '/doc.json' + jsonb.supportSparseArray = true + util.saveFile(docPath, jsonb.beautify(results)) + + local mdPath = doc2md.buildMD(outputPath) + return docPath, mdPath +end + +---@async +---@param outputPath string +function export.makeDoc(outputPath) ws.awaitReady(ws.rootUri) local expandAlias = config.get(ws.rootUri, 'Lua.hover.expandAlias') @@ -265,32 +291,11 @@ function export.makeDoc(outputPath) await.sleep(0.1) local prog <close> = progress.create(ws.rootUri, '正在生成文档...', 0) - local globalTypes = vm.getGlobals 'type' - local globalVars = vm.getGlobals 'variable' - - local max = #globalTypes + #globalVars - - for i, global in ipairs(globalTypes) do - collectTypes(global, results) + local docPath, mdPath = export.export(outputPath, function (i, max) 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 + prog:setPercentage((i) / max * 100) end) - local docPath = outputPath .. '/doc.json' - jsonb.supportSparseArray = true - util.saveFile(docPath, jsonb.beautify(results)) - - local mdPath = doc2md.buildMD(outputPath) return docPath, mdPath end @@ -313,7 +318,6 @@ function export.runCLI() util.enableCloseFunction() local lastClock = os.clock() - local results = {} ---@async lclient():start(function (client) @@ -331,11 +335,7 @@ function export.runCLI() ws.awaitReady(rootUri) await.sleep(0.1) - local globals = vm.getGlobals 'type' - - local max = #globals - for i, global in ipairs(globals) do - collectTypes(global, results) + local docPath, mdPath = export.export(LOGPATH, function (i, max) if os.clock() - lastClock > 0.2 then lastClock = os.clock() local output = '\x0D' @@ -346,24 +346,15 @@ function export.runCLI() .. tostring(i) .. '/' .. tostring(max) io.write(output) end - end - io.write('\x0D') - - table.sort(results, function (a, b) - return a.name < b.name end) - end) - - local docPath = LOGPATH .. '/doc.json' - jsonb.supportSparseArray = true - util.saveFile(docPath, jsonb.beautify(results)) - local mdPath = doc2md.buildMD(LOGPATH) + io.write('\x0D') - print(lang.script('CLI_DOC_DONE' - , ('[%s](%s)'):format(files.normalize(docPath), furi.encode(docPath)) - , ('[%s](%s)'):format(files.normalize(mdPath), furi.encode(mdPath)) - )) + print(lang.script('CLI_DOC_DONE' + , ('[%s](%s)'):format(files.normalize(docPath), furi.encode(docPath)) + , ('[%s](%s)'):format(files.normalize(mdPath), furi.encode(mdPath)) + )) + end) end return export |