diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-07 20:40:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-07 20:40:30 +0800 |
commit | 75f16e1b10a853a10084aa7bf8582259cc1e092e (patch) | |
tree | 0844646cd0104fd0f6ea9922f4745a951ad018c2 /script/config/template.lua | |
parent | 85d497ac617dcb629b991defc23540e9bfa34cbc (diff) | |
download | lua-language-server-75f16e1b10a853a10084aa7bf8582259cc1e092e.zip |
cleanup
Diffstat (limited to 'script/config/template.lua')
-rw-r--r-- | script/config/template.lua | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/script/config/template.lua b/script/config/template.lua new file mode 100644 index 00000000..c84a6719 --- /dev/null +++ b/script/config/template.lua @@ -0,0 +1,229 @@ +local util = require 'utility' +local define = require 'proto.define' + +---@class config.unit +---@field caller function +local mt = {} +mt.__index = mt + +function mt:__call(...) + self:caller(...) + return self +end + +function mt:__shr(default) + self.default = default + return self +end + +local units = {} + +local function register(name, default, checker, loader, caller) + units[name] = { + default = default, + checker = checker, + loader = loader, + caller = caller, + } +end + +local Type = setmetatable({}, { __index = function (_, name) + local unit = {} + for k, v in pairs(units[name]) do + unit[k] = v + end + return setmetatable(unit, mt) +end }) + +register('Boolean', false, function (self, v) + return type(v) == 'boolean' +end, function (self, v) + return v +end) + +register('Integer', 0, function (self, v) + return type(v) == 'number' +end, function (self, v) + return math.floor(v) +end) + +register('String', '', function (self, v) + return type(v) == 'string' +end, function (self, v) + return tostring(v) +end) + +register('Nil', nil, function (self, v) + return type(v) == 'nil' +end, function (self, v) + return nil +end) + +register('Array', {}, function (self, value) + return type(value) == 'table' +end, function (self, value) + local t = {} + for _, v in ipairs(value) do + if self.sub:checker(v) then + t[#t+1] = self.sub:loader(v) + end + end + return t +end, function (self, sub) + self.sub = sub +end) + +register('Hash', {}, function (self, value) + if type(value) == 'table' then + if #value == 0 then + for k, v in pairs(value) do + if not self.subkey:checker(k) + or not self.subvalue:checker(v) then + return false + end + end + else + if not self.subvalue:checker(true) then + return false + end + for _, v in ipairs(value) do + if not self.subkey:checker(v) then + return false + end + end + end + return true + end + if type(value) == 'string' then + return self.subkey:checker('') + and self.subvalue:checker(true) + end +end, function (self, value) + if type(value) == 'table' then + local t = {} + if #value == 0 then + for k, v in pairs(value) do + t[k] = v + end + else + for _, k in pairs(value) do + t[k] = true + end + end + return t + end + if type(value) == 'string' then + local t = {} + for s in value:gmatch('[^' .. self.sep .. ']+') do + t[s] = true + end + return t + end +end, function (self, subkey, subvalue, sep) + self.subkey = subkey + self.subvalue = subvalue + self.sep = sep +end) + +register('Or', nil, function (self, value) + for _, sub in ipairs(self.subs) do + if sub:checker(value) then + return true + end + end + return false +end, function (self, value) + for _, sub in ipairs(self.subs) do + if sub:checker(value) then + return sub:loader(value) + end + end +end, function (self, ...) + self.subs = { ... } +end) + +local template = { + ['Lua.runtime.version'] = Type.String >> 'Lua 5.4', + ['Lua.runtime.path'] = Type.Array(Type.String) >> { + "?.lua", + "?/init.lua", + }, + ['Lua.runtime.pathStrict'] = Type.Boolean >> false, + ['Lua.runtime.special'] = Type.Hash(Type.String, Type.String), + ['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}', + ['Lua.runtime.unicodeName'] = Type.Boolean, + ['Lua.runtime.nonstandardSymbol'] = Type.Hash(Type.String, Type.Boolean, ';'), + ['Lua.runtime.plugin'] = Type.String, + ['Lua.runtime.fileEncoding'] = Type.String >> 'utf8', + ['Lua.runtime.builtin'] = Type.Hash(Type.String, Type.String), + ['Lua.diagnostics.enable'] = Type.Boolean >> true, + ['Lua.diagnostics.globals'] = Type.Hash(Type.String, Type.Boolean, ';'), + ['Lua.diagnostics.disable'] = Type.Hash(Type.String, Type.Boolean, ';'), + ['Lua.diagnostics.severity'] = Type.Hash(Type.String, Type.String) + >> util.deepCopy(define.DiagnosticDefaultSeverity), + ['Lua.diagnostics.neededFileStatus'] = Type.Hash(Type.String, Type.String) + >> util.deepCopy(define.DiagnosticDefaultNeededFileStatus), + ['Lua.diagnostics.disableScheme'] = Type.Hash(Type.String, Type.Boolean, ';') >> { + ['git'] = true, + }, + ['Lua.diagnostics.workspaceDelay'] = Type.Integer >> 5, + ['Lua.diagnostics.workspaceRate'] = Type.Integer >> 100, + ['Lua.diagnostics.libraryFiles'] = Type.String >> 'Opened', + ['Lua.diagnostics.ignoredFiles'] = Type.String >> 'Opened', + ['Lua.workspace.ignoreDir'] = Type.Array(Type.String), + ['Lua.workspace.ignoreSubmodules'] = Type.Boolean >> true, + ['Lua.workspace.useGitIgnore'] = Type.Boolean >> true, + ['Lua.workspace.maxPreload'] = Type.Integer >> 3000, + ['Lua.workspace.preloadFileSize'] = Type.Integer >> 500, + ['Lua.workspace.library'] = Type.Hash(Type.String, Type.Boolean, ';'), + ['Lua.workspace.checkThirdParty'] = Type.Boolean >> true, + ['Lua.workspace.userThirdParty'] = Type.Array(Type.String), + ['Lua.workspace.supportScheme'] = Type.Hash(Type.String, Type.Boolean, ';') >> { + ['file'] = true, + ['untitled'] = true, + ['git'] = true, + }, + ['Lua.completion.enable'] = Type.Boolean >> true, + ['Lua.completion.callSnippet'] = Type.String >> 'Disable', + ['Lua.completion.keywordSnippet'] = Type.String >> 'Replace', + ['Lua.completion.displayContext'] = Type.Integer >> 0, + ['Lua.completion.workspaceWord'] = Type.Boolean >> true, + ['Lua.completion.showWord'] = Type.String >> 'Fallback', + ['Lua.completion.autoRequire'] = Type.Boolean >> true, + ['Lua.completion.showParams'] = Type.Boolean >> true, + ['Lua.completion.requireSeparator'] = Type.String >> '.', + ['Lua.completion.postfix'] = Type.String >> '@', + ['Lua.signatureHelp.enable'] = Type.Boolean >> true, + ['Lua.hover.enable'] = Type.Boolean >> true, + ['Lua.hover.viewString'] = Type.Boolean >> true, + ['Lua.hover.viewStringMax'] = Type.Integer >> 1000, + ['Lua.hover.viewNumber'] = Type.Boolean >> true, + ['Lua.hover.previewFields'] = Type.Integer >> 20, + ['Lua.hover.enumsLimit'] = Type.Integer >> 5, + ['Lua.hover.expandAlias'] = Type.Boolean >> true, + ['Lua.semantic.enable'] = Type.Boolean >> true, + ['Lua.semantic.variable'] = Type.Boolean >> true, + ['Lua.semantic.annotation'] = Type.Boolean >> true, + ['Lua.semantic.keyword'] = Type.Boolean >> false, + ['Lua.hint.enable'] = Type.Boolean >> false, + ['Lua.hint.paramType'] = Type.Boolean >> true, + ['Lua.hint.setType'] = Type.Boolean >> false, + ['Lua.hint.paramName'] = Type.String >> 'All', + ['Lua.hint.await'] = Type.Boolean >> true, + ['Lua.hint.arrayIndex'] = Type.Boolean >> 'Auto', + ['Lua.window.statusBar'] = Type.Boolean >> true, + ['Lua.window.progressBar'] = Type.Boolean >> true, + ['Lua.format.enable'] = Type.Boolean >> true, + ['Lua.format.defaultConfig'] = Type.Hash(Type.String, Type.String) + >> {}, + ['Lua.spell.dict'] = Type.Array(Type.String), + ['Lua.telemetry.enable'] = Type.Or(Type.Boolean >> false, Type.Nil) >> nil, + + -- VSCode + ['files.associations'] = Type.Hash(Type.String, Type.String), + ['files.exclude'] = Type.Hash(Type.String, Type.Boolean), + ['editor.semanticHighlighting.enabled'] = Type.Or(Type.Boolean, Type.String), + ['editor.acceptSuggestionOnEnter'] = Type.String >> 'on', +} + +return template |