@@ -264,12 +264,26 @@ local function collectVars(global, results)
264
264
results [# results + 1 ] = result
265
265
end
266
266
267
+ --- Add config settings to JSON output.
268
+ --- @param results table
269
+ local function collectConfig (results )
270
+ local result = {
271
+ name = ' LuaLS' ,
272
+ type = ' luals.config' ,
273
+ DOC = fs .absolute (fs .path (DOC )):string (),
274
+ defines = {},
275
+ fields = {}
276
+ }
277
+ results [# results + 1 ] = result
278
+ end
279
+
267
280
--- @async
268
281
--- @param callback fun ( i , max )
269
282
function export .export (outputPath , callback )
270
283
local results = {}
271
284
local globals = vm .getAllGlobals ()
272
285
286
+ collectConfig (results )
273
287
local max = 0
274
288
for _ in pairs (globals ) do
275
289
max = max + 1
@@ -331,9 +345,53 @@ function export.makeDoc(outputPath)
331
345
return docPath , mdPath
332
346
end
333
347
348
+
349
+ --- Find file 'doc.json'.
350
+ --- @return fs.path
351
+ local function findDocJson ()
352
+ local doc_json_path
353
+ if type (DOC_UPDATE ) == ' string' then
354
+ doc_json_path = fs .absolute (fs .path (DOC_UPDATE )) .. ' /doc.json'
355
+ else
356
+ doc_json_path = fs .current_path () .. ' /doc.json'
357
+ end
358
+ if fs .exists (doc_json_path ) then
359
+ return doc_json_path
360
+ else
361
+ error (string.format (' Error: File "%s" not found.' , doc_json_path ))
362
+ end
363
+ end
364
+
365
+ --- @return string # path of 'doc.json'
366
+ --- @return string # path to be documented
367
+ local function getPathDocUpdate ()
368
+ local doc_json_path = findDocJson ()
369
+ local ok , doc_path = pcall (
370
+ function ()
371
+ local json = require (' json' )
372
+ local json_file = io.open (doc_json_path :string (), ' r' ):read (' *all' )
373
+ local json_data = json .decode (json_file )
374
+ for _ , section in ipairs (json_data ) do
375
+ if section .type == ' luals.config' then
376
+ return section .DOC
377
+ end
378
+ end
379
+ end )
380
+ if ok then
381
+ local doc_json_dir = doc_json_path :string ():gsub (' /doc.json' , ' ' )
382
+ return doc_json_dir , doc_path
383
+ else
384
+ error (string.format (' Error: Cannot update "%s".' , doc_json_path .. ' /doc.json' ))
385
+ end
386
+ end
387
+
334
388
function export .runCLI ()
335
389
lang (LOCALE )
336
390
391
+ if DOC_UPDATE then
392
+ DOC_OUT_PATH , DOC = getPathDocUpdate ()
393
+ end
394
+
337
395
if type (DOC ) ~= ' string' then
338
396
print (lang .script (' CLI_CHECK_ERROR_TYPE' , type (DOC )))
339
397
return
0 commit comments