summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-03-13 17:22:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-03-13 17:22:20 +0800
commita2cc1076556bde7ed91036926c5007e4ac66b0d2 (patch)
tree9b6ad35faf66d9e0cf0c0de9954924a94421ad60 /script
parent6d79a662a4d1f95a80d29af46eaae5ff9a659341 (diff)
downloadlua-language-server-a2cc1076556bde7ed91036926c5007e4ac66b0d2.zip
export all globals
fix #1943
Diffstat (limited to 'script')
-rw-r--r--script/cli/doc.lua88
1 files changed, 42 insertions, 46 deletions
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