diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-03-13 17:22:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-03-13 17:22:20 +0800 |
commit | a2cc1076556bde7ed91036926c5007e4ac66b0d2 (patch) | |
tree | 9b6ad35faf66d9e0cf0c0de9954924a94421ad60 | |
parent | 6d79a662a4d1f95a80d29af46eaae5ff9a659341 (diff) | |
download | lua-language-server-a2cc1076556bde7ed91036926c5007e4ac66b0d2.zip |
export all globals
fix #1943
-rw-r--r-- | changelog.md | 5 | ||||
-rw-r--r-- | script/cli/doc.lua | 88 |
2 files changed, 47 insertions, 46 deletions
diff --git a/changelog.md b/changelog.md index 5009ced8..a0ad84a5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # changelog +## 3.6.18 +* `FIX` [#1943] + +[#1943]: https://github.com/LuaLS/lua-language-server/issues/1943 + ## 3.6.17 `2023-3-9` * `CHG` export documents: export global variables diff --git a/script/cli/doc.lua b/script/cli/doc.lua index 0ceaff83..f94a2066 100644 --- a/script/cli/doc.lua +++ b/script/cli/doc.lua @@ -245,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') @@ -260,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 @@ -308,7 +318,6 @@ function export.runCLI() util.enableCloseFunction() local lastClock = os.clock() - local results = {} ---@async lclient():start(function (client) @@ -326,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' @@ -341,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 |