diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-08 17:16:22 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-08 17:16:22 +0800 |
commit | a73b2d1ab864642d70c3676769e1faf1369daad8 (patch) | |
tree | d67781673c77c68ff912bdefaad30c06ed1bbbde | |
parent | e96350421a66ac8490fa61336dcacd67413dd2e8 (diff) | |
download | lua-language-server-a73b2d1ab864642d70c3676769e1faf1369daad8.zip |
build config
-rw-r--r-- | .vscode/launch.json | 17 | ||||
-rw-r--r-- | script/config/template.lua | 1 | ||||
-rw-r--r-- | tools/build-doc.lua | 4 | ||||
-rw-r--r-- | tools/configuration.lua | 99 |
4 files changed, 121 insertions, 0 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c4a7b19..71d8735a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -88,5 +88,22 @@ "stderr", ], }, + { + "name": "🀄build-doc", + "type": "lua", + "request": "launch", + "stopOnEntry": false, + "luaexe": "${workspaceFolder}/bin/lua-language-server", + "program": "${workspaceRoot}/tools/build-doc.lua", + "cpath": "${workspaceFolder}/bin/?.dll", + "arg": [ + ], + "luaVersion": "latest", + "sourceCoding": "utf8", + "outputCapture": [ + "print", + "stderr", + ], + }, ] } diff --git a/script/config/template.lua b/script/config/template.lua index c37a6262..4be798ef 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -14,6 +14,7 @@ end function mt:__shr(default) self.default = default + self.hasDefault = true return self end diff --git a/tools/build-doc.lua b/tools/build-doc.lua new file mode 100644 index 00000000..f0331872 --- /dev/null +++ b/tools/build-doc.lua @@ -0,0 +1,4 @@ +package.path = package.path .. ';script/?.lua;tools/?.lua' + +local config = require 'configuration' + diff --git a/tools/configuration.lua b/tools/configuration.lua new file mode 100644 index 00000000..8d7cac5d --- /dev/null +++ b/tools/configuration.lua @@ -0,0 +1,99 @@ +local json = require 'json' +local template = require 'config.template' + +local function getType(temp) + if temp.name == 'Boolean' then + return 'boolean' + end + if temp.name == 'String' then + return 'string' + end + if temp.name == 'Integer' then + return 'integer' + end + if temp.name == 'Nil' then + return 'null' + end + if temp.name == 'Array' then + return 'array' + end + if temp.name == 'Hash' then + return 'object' + end + if temp.name == 'Or' then + return { getType(temp.subs[1]), getType(temp.subs[2]) } + end + error('Unknown type: ' .. temp.name) +end + +local function getDefault(temp) + local default = temp.default + if default == nil and temp.hasDefault then + default = json.null + end + return default +end + +local function getEnum(temp) + return temp.enums +end + +local function getEnumDesc(name, temp) + if not temp.enums then + return nil + end + local descs = {} + + for _, enum in ipairs(temp.enums) do + descs[#descs+1] = name:gsub('^Lua', '%%config') .. '.' .. enum .. '%' + end + + return descs +end + +local function insertArray(conf, temp) + conf.items = { + type = getType(temp.sub), + } +end + +local function insertHash(conf, temp) + conf.additionalProperties = false + if not temp.subkey.enums then + if temp.subvalue.enums then + conf.patternProperties = { + ['.*'] = { + type = getType( temp.subvalue), + default = getDefault( temp.subvalue), + enum = getEnum( temp.subvalue), + } + } + end + end +end + +local config = {} + +for name, temp in pairs(template) do + config[name] = { + scope = 'resource', + type = getType(temp), + default = getDefault(temp), + enum = getEnum(temp), + + markdownDescription = name:gsub('^Lua', '%%config') .. '%', + markdownEnumDescriptions = getEnumDesc(name, temp), + } + + if temp.name == 'Array' then + insertArray(config[name], temp) + end + + if temp.name == 'Hash' then + insertHash(config[name], temp) + end +end + +config['Lua.telemetry.enable'].tags = { 'telemetry' } + +return config |