@@ -278,12 +278,26 @@ local function collectVars(global, results)
278
278
results [# results + 1 ] = result
279
279
end
280
280
281
+ --- Add config settings to JSON output.
282
+ --- @param results table
283
+ local function collectConfig (results )
284
+ local result = {
285
+ name = ' LuaLS' ,
286
+ type = ' luals.config' ,
287
+ DOC = fs .absolute (fs .path (DOC )):string (),
288
+ defines = {},
289
+ fields = {}
290
+ }
291
+ results [# results + 1 ] = result
292
+ end
293
+
281
294
--- @async
282
295
--- @param callback fun ( i , max )
283
296
function export .export (outputPath , callback )
284
297
local results = {}
285
298
local globals = vm .getAllGlobals ()
286
299
300
+ collectConfig (results )
287
301
local max = 0
288
302
for _ in pairs (globals ) do
289
303
max = max + 1
@@ -345,9 +359,53 @@ function export.makeDoc(outputPath)
345
359
return docPath , mdPath
346
360
end
347
361
362
+
363
+ --- Find file 'doc.json'.
364
+ --- @return fs.path
365
+ local function findDocJson ()
366
+ local doc_json_path
367
+ if type (DOC_UPDATE ) == ' string' then
368
+ doc_json_path = fs .absolute (fs .path (DOC_UPDATE )) .. ' /doc.json'
369
+ else
370
+ doc_json_path = fs .current_path () .. ' /doc.json'
371
+ end
372
+ if fs .exists (doc_json_path ) then
373
+ return doc_json_path
374
+ else
375
+ error (string.format (' Error: File "%s" not found.' , doc_json_path ))
376
+ end
377
+ end
378
+
379
+ --- @return string # path of 'doc.json'
380
+ --- @return string # path to be documented
381
+ local function getPathDocUpdate ()
382
+ local doc_json_path = findDocJson ()
383
+ local ok , doc_path = pcall (
384
+ function ()
385
+ local json = require (' json' )
386
+ local json_file = io.open (doc_json_path :string (), ' r' ):read (' *all' )
387
+ local json_data = json .decode (json_file )
388
+ for _ , section in ipairs (json_data ) do
389
+ if section .type == ' luals.config' then
390
+ return section .DOC
391
+ end
392
+ end
393
+ end )
394
+ if ok then
395
+ local doc_json_dir = doc_json_path :string ():gsub (' /doc.json' , ' ' )
396
+ return doc_json_dir , doc_path
397
+ else
398
+ error (string.format (' Error: Cannot update "%s".' , doc_json_path .. ' /doc.json' ))
399
+ end
400
+ end
401
+
348
402
function export .runCLI ()
349
403
lang (LOCALE )
350
404
405
+ if DOC_UPDATE then
406
+ DOC_OUT_PATH , DOC = getPathDocUpdate ()
407
+ end
408
+
351
409
if type (DOC ) ~= ' string' then
352
410
print (lang .script (' CLI_CHECK_ERROR_TYPE' , type (DOC )))
353
411
return
0 commit comments