summaryrefslogtreecommitdiff
path: root/script/cli
diff options
context:
space:
mode:
Diffstat (limited to 'script/cli')
-rw-r--r--script/cli/doc.lua58
-rw-r--r--script/cli/init.lua5
2 files changed, 63 insertions, 0 deletions
diff --git a/script/cli/doc.lua b/script/cli/doc.lua
index 7b1cdca2..7ba3ae68 100644
--- a/script/cli/doc.lua
+++ b/script/cli/doc.lua
@@ -272,12 +272,26 @@ local function collectVars(global, results)
results[#results+1] = result
end
+---Add config settings to JSON output.
+---@param results table
+local function collectConfig(results)
+ local result = {
+ name = 'LuaLS',
+ type = 'luals.config',
+ DOC = fs.absolute(fs.path(DOC)):string(),
+ defines = {},
+ fields = {}
+ }
+ results[#results+1] = result
+end
+
---@async
---@param callback fun(i, max)
function export.export(outputPath, callback)
local results = {}
local globals = vm.getAllGlobals()
+ collectConfig(results)
local max = 0
for _ in pairs(globals) do
max = max + 1
@@ -339,9 +353,53 @@ function export.makeDoc(outputPath)
return docPath, mdPath
end
+
+---Find file 'doc.json'.
+---@return fs.path
+local function findDocJson()
+ local doc_json_path
+ if type(DOC_UPDATE) == 'string' then
+ doc_json_path = fs.absolute(fs.path(DOC_UPDATE)) .. '/doc.json'
+ else
+ doc_json_path = fs.current_path() .. '/doc.json'
+ end
+ if fs.exists(doc_json_path) then
+ return doc_json_path
+ else
+ error(string.format('Error: File "%s" not found.', doc_json_path))
+ end
+end
+
+---@return string # path of 'doc.json'
+---@return string # path to be documented
+local function getPathDocUpdate()
+ local doc_json_path = findDocJson()
+ local ok, doc_path = pcall(
+ function ()
+ local json = require('json')
+ local json_file = io.open(doc_json_path:string(), 'r'):read('*all')
+ local json_data = json.decode(json_file)
+ for _, section in ipairs(json_data) do
+ if section.type == 'luals.config' then
+ return section.DOC
+ end
+ end
+ end)
+ if ok then
+ local doc_json_dir = doc_json_path:string():gsub('/doc.json', '')
+ return doc_json_dir, doc_path
+ else
+ error(string.format('Error: Cannot update "%s".', doc_json_path .. '/doc.json'))
+ end
+end
+
function export.runCLI()
lang(LOCALE)
+ if DOC_UPDATE then
+ DOC_OUT_PATH, DOC = getPathDocUpdate()
+ end
+
if type(DOC) ~= 'string' then
print(lang.script('CLI_CHECK_ERROR_TYPE', type(DOC)))
return
diff --git a/script/cli/init.lua b/script/cli/init.lua
index 6d7fc0ff..d37c50ae 100644
--- a/script/cli/init.lua
+++ b/script/cli/init.lua
@@ -8,6 +8,11 @@ if _G['CHECK'] then
os.exit(0, true)
end
+if _G['DOC_UPDATE'] then
+ require 'cli.doc' .runCLI()
+ os.exit(0, true)
+end
+
if _G['DOC'] then
require 'cli.doc' .runCLI()
os.exit(0, true)