@@ -245,10 +245,41 @@ local function collectVars(global, results)
245
245
end
246
246
247
247
--- @async
248
- --- @param outputPath string
249
- function export .makeDoc (outputPath )
248
+ --- @param callback fun ( i , max )
249
+ function export .export (outputPath , callback )
250
250
local results = {}
251
+ local globals = vm .getAllGlobals ()
252
+
253
+ local max = 0
254
+ for _ in pairs (globals ) do
255
+ max = max + 1
256
+ end
257
+ local i = 0
258
+ for _ , global in pairs (globals ) do
259
+ if global .cate == ' variable' then
260
+ collectVars (global , results )
261
+ elseif global .cate == ' type' then
262
+ collectTypes (global , results )
263
+ end
264
+ i = i + 1
265
+ callback (i , max )
266
+ end
267
+
268
+ table.sort (results , function (a , b )
269
+ return a .name < b .name
270
+ end )
271
+
272
+ local docPath = outputPath .. ' /doc.json'
273
+ jsonb .supportSparseArray = true
274
+ util .saveFile (docPath , jsonb .beautify (results ))
275
+
276
+ local mdPath = doc2md .buildMD (outputPath )
277
+ return docPath , mdPath
278
+ end
251
279
280
+ --- @async
281
+ --- @param outputPath string
282
+ function export .makeDoc (outputPath )
252
283
ws .awaitReady (ws .rootUri )
253
284
254
285
local expandAlias = config .get (ws .rootUri , ' Lua.hover.expandAlias' )
@@ -260,32 +291,11 @@ function export.makeDoc(outputPath)
260
291
await .sleep (0.1 )
261
292
262
293
local prog <close> = progress .create (ws .rootUri , ' 正在生成文档...' , 0 )
263
- local globalTypes = vm .getGlobals ' type'
264
- local globalVars = vm .getGlobals ' variable'
265
-
266
- local max = # globalTypes + # globalVars
267
-
268
- for i , global in ipairs (globalTypes ) do
269
- collectTypes (global , results )
294
+ local docPath , mdPath = export .export (outputPath , function (i , max )
270
295
prog :setMessage ((' %d/%d' ):format (i , max ))
271
- prog :setPercentage (i / max * 100 )
272
- end
273
-
274
- for i , global in ipairs (globalVars ) do
275
- collectVars (global , results )
276
- prog :setMessage ((' %d/%d' ):format (i + # globalTypes , max ))
277
- prog :setPercentage ((i + # globalTypes ) / max * 100 )
278
- end
279
-
280
- table.sort (results , function (a , b )
281
- return a .name < b .name
296
+ prog :setPercentage ((i ) / max * 100 )
282
297
end )
283
298
284
- local docPath = outputPath .. ' /doc.json'
285
- jsonb .supportSparseArray = true
286
- util .saveFile (docPath , jsonb .beautify (results ))
287
-
288
- local mdPath = doc2md .buildMD (outputPath )
289
299
return docPath , mdPath
290
300
end
291
301
@@ -308,7 +318,6 @@ function export.runCLI()
308
318
util .enableCloseFunction ()
309
319
310
320
local lastClock = os.clock ()
311
- local results = {}
312
321
313
322
--- @async
314
323
lclient ():start (function (client )
@@ -326,11 +335,7 @@ function export.runCLI()
326
335
ws .awaitReady (rootUri )
327
336
await .sleep (0.1 )
328
337
329
- local globals = vm .getGlobals ' type'
330
-
331
- local max = # globals
332
- for i , global in ipairs (globals ) do
333
- collectTypes (global , results )
338
+ local docPath , mdPath = export .export (LOGPATH , function (i , max )
334
339
if os.clock () - lastClock > 0.2 then
335
340
lastClock = os.clock ()
336
341
local output = ' \x0D '
@@ -341,24 +346,15 @@ function export.runCLI()
341
346
.. tostring (i ) .. ' /' .. tostring (max )
342
347
io.write (output )
343
348
end
344
- end
345
- io.write (' \x0D ' )
346
-
347
- table.sort (results , function (a , b )
348
- return a .name < b .name
349
349
end )
350
- end )
351
-
352
- local docPath = LOGPATH .. ' /doc.json'
353
- jsonb .supportSparseArray = true
354
- util .saveFile (docPath , jsonb .beautify (results ))
355
350
356
- local mdPath = doc2md . buildMD ( LOGPATH )
351
+ io.write ( ' \x0D ' )
357
352
358
- print (lang .script (' CLI_DOC_DONE'
359
- , (' [%s](%s)' ):format (files .normalize (docPath ), furi .encode (docPath ))
360
- , (' [%s](%s)' ):format (files .normalize (mdPath ), furi .encode (mdPath ))
361
- ))
353
+ print (lang .script (' CLI_DOC_DONE'
354
+ , (' [%s](%s)' ):format (files .normalize (docPath ), furi .encode (docPath ))
355
+ , (' [%s](%s)' ):format (files .normalize (mdPath ), furi .encode (mdPath ))
356
+ ))
357
+ end )
362
358
end
363
359
364
360
return export
0 commit comments