dotfiles from arch

This commit is contained in:
2025-09-28 11:39:12 +02:00
parent 75885729cd
commit d1c6923bbb
1358 changed files with 575835 additions and 0 deletions

View File

@@ -0,0 +1,276 @@
local util = require 'utility'
local timer = require 'timer'
local scope = require 'workspace.scope'
local template = require 'config.template'
---@alias config.source '"client"'|'"path"'|'"local"'
---@class config.api
local m = {}
m.watchList = {}
m.NULL = {}
m.nullSymbols = {
[m.NULL] = true,
}
---@param scp scope
---@param key string
---@param nowValue any
---@param rawValue any
local function update(scp, key, nowValue, rawValue)
local now = m.getNowTable(scp)
local raw = m.getRawTable(scp)
now[key] = nowValue
raw[key] = rawValue
end
---@param uri? uri
---@param key? string
---@return scope
local function getScope(uri, key)
local raw = m.getRawTable(scope.override)
if raw then
if not key or raw[key] ~= nil then
return scope.override
end
end
if uri then
---@type scope?
local scp = scope.getFolder(uri) or scope.getLinkedScope(uri)
if scp then
if not key
or m.getRawTable(scp)[key] ~= nil then
return scp
end
end
end
return scope.fallback
end
---@param scp scope
---@param key string
---@param value any
function m.setByScope(scp, key, value)
local unit = template[key]
if not unit then
return false
end
local raw = m.getRawTable(scp)
if util.equal(raw[key], value) then
return false
end
if unit:checker(value) then
update(scp, key, unit:loader(value), value)
else
update(scp, key, unit.default, unit.default)
end
return true
end
---@param uri? uri
---@param key string
---@param value any
function m.set(uri, key, value)
local unit = template[key]
assert(unit, 'unknown key: ' .. key)
local scp = getScope(uri, key)
local oldValue = m.get(uri, key)
m.setByScope(scp, key, value)
local newValue = m.get(uri, key)
if not util.equal(oldValue, newValue) then
m.event(uri, key, newValue, oldValue)
return true
end
return false
end
function m.add(uri, key, value)
local unit = template[key]
assert(unit, 'unknown key: ' .. key)
local list = m.getRaw(uri, key)
assert(type(list) == 'table', 'not a list: ' .. key)
local copyed = {}
for i, v in ipairs(list) do
if util.equal(v, value) then
return false
end
copyed[i] = v
end
copyed[#copyed+1] = value
local oldValue = m.get(uri, key)
m.set(uri, key, copyed)
local newValue = m.get(uri, key)
if not util.equal(oldValue, newValue) then
m.event(uri, key, newValue, oldValue)
return true
end
return false
end
function m.remove(uri, key, value)
local unit = template[key]
assert(unit, 'unknown key: ' .. key)
local list = m.getRaw(uri, key)
assert(type(list) == 'table', 'not a list: ' .. key)
local copyed = {}
for i, v in ipairs(list) do
if not util.equal(v, value) then
copyed[i] = v
end
end
local oldValue = m.get(uri, key)
m.set(uri, key, copyed)
local newValue = m.get(uri, key)
if not util.equal(oldValue, newValue) then
m.event(uri, key, newValue, oldValue)
return true
end
return false
end
function m.prop(uri, key, prop, value)
local unit = template[key]
assert(unit, 'unknown key: ' .. key)
local map = m.getRaw(uri, key)
assert(type(map) == 'table', 'not a map: ' .. key)
if util.equal(map[prop], value) then
return false
end
local copyed = {}
for k, v in pairs(map) do
copyed[k] = v
end
copyed[prop] = value
local oldValue = m.get(uri, key)
m.set(uri, key, copyed)
local newValue = m.get(uri, key)
if not util.equal(oldValue, newValue) then
m.event(uri, key, newValue, oldValue)
return true
end
return false
end
---@param uri? uri
---@param key string
---@return any
function m.get(uri, key)
local scp = getScope(uri, key)
local value = m.getNowTable(scp)[key]
if value == nil then
value = template[key].default
end
if value == m.NULL then
value = nil
end
return value
end
---@param uri uri
---@param key string
---@return any
function m.getRaw(uri, key)
local scp = getScope(uri, key)
local value = m.getRawTable(scp)[key]
if value == nil then
value = template[key].default
end
if value == m.NULL then
value = nil
end
return value
end
---@param scp scope
function m.getNowTable(scp)
return scp:get 'config.now'
or scp:set('config.now', {})
end
---@param scp scope
function m.getRawTable(scp)
return scp:get 'config.raw'
or scp:set('config.raw', {})
end
---@param scp scope
---@param ... table
function m.update(scp, ...)
local oldConfig = m.getNowTable(scp)
local newConfig = {}
scp:set('config.now', newConfig)
scp:set('config.raw', {})
local function expand(t, left)
for key, value in pairs(t) do
local fullKey = key
if left then
fullKey = left .. '.' .. key
end
if m.nullSymbols[value] then
value = m.NULL
end
if template[fullKey] then
m.setByScope(scp, fullKey, value)
elseif template['Lua.' .. fullKey] then
m.setByScope(scp, 'Lua.' .. fullKey, value)
elseif type(value) == 'table' then
expand(value, fullKey)
end
end
end
local news = table.pack(...)
for i = 1, news.n do
if type(news[i]) == 'table' then
expand(news[i])
end
end
-- compare then fire event
if oldConfig then
for key, oldValue in pairs(oldConfig) do
local newValue = newConfig[key]
if not util.equal(oldValue, newValue) then
m.event(scp.uri, key, newValue, oldValue)
end
end
end
m.event(scp.uri, '')
end
---@param callback fun(uri: uri, key: string, value: any, oldValue: any)
function m.watch(callback)
m.watchList[#m.watchList+1] = callback
end
function m.event(uri, key, value, oldValue)
if not m.changes then
m.changes = {}
timer.wait(0, function ()
local delay = m.changes
m.changes = nil
for _, info in ipairs(delay) do
for _, callback in ipairs(m.watchList) do
callback(info.uri, info.key, info.value, info.oldValue)
end
end
end)
end
m.changes[#m.changes+1] = {
uri = uri,
key = key,
value = value,
oldValue = oldValue,
}
end
function m.addNullSymbol(null)
m.nullSymbols[null] = true
end
return m

View File

@@ -0,0 +1,67 @@
-- Handles loading environment arguments
---Convert a string to boolean
---@param v string
local function strToBool(v)
return v == "true"
end
---ENV args are defined here.
---- `name` is the ENV arg name
---- `key` is the value used to index `_G` for setting the argument
---- `converter` if present, will be used to convert the string value into another type
---@type { name: string, key: string, converter: fun(value: string): any }[]
local vars = {
{
name = "LLS_CHECK_LEVEL",
key = "CHECKLEVEL",
},
{
name = "LLS_CHECK_PATH",
key = "CHECK",
},
{
name = "LLS_CONFIG_PATH",
key = "CONFIGPATH",
},
{
name = "LLS_DOC_OUT_PATH",
key = "DOC_OUT_PATH",
},
{
name = "LLS_DOC_PATH",
key = "DOC",
},
{
name = "LLS_FORCE_ACCEPT_WORKSPACE",
key = "FORCE_ACCEPT_WORKSPACE",
converter = strToBool,
},
{
name = "LLS_LOCALE",
key = "LOCALE",
},
{
name = "LLS_LOG_LEVEL",
key = "LOGLEVEL",
},
{
name = "LLS_LOG_PATH",
key = "LOGPATH",
},
{
name = "LLS_META_PATH",
key = "METAPATH",
},
}
for _, var in ipairs(vars) do
local value = os.getenv(var.name)
if value then
if var.converter then
value = var.converter(value)
end
_G[var.key] = value
end
end

View File

@@ -0,0 +1,3 @@
local config = require 'config.config'
return config

View File

@@ -0,0 +1,131 @@
local proto = require 'proto'
local lang = require 'language'
local util = require 'utility'
local workspace = require 'workspace'
local scope = require 'workspace.scope'
local inspect = require 'inspect'
local jsonc = require 'jsonc'
local function errorMessage(msg)
proto.notify('window/showMessage', {
type = 3,
message = msg,
})
log.error(msg)
end
---@class config.loader
local m = {}
---@return table?
function m.loadRCConfig(uri, filename)
local scp = scope.getScope(uri)
local path = workspace.getAbsolutePath(uri, filename)
if not path then
scp:set('lastRCConfig', nil)
return nil
end
local buf = util.loadFile(path)
if not buf then
scp:set('lastRCConfig', nil)
return nil
end
local suc, res = pcall(jsonc.decode_jsonc, buf)
if not suc then
errorMessage(lang.script('CONFIG_LOAD_ERROR', res))
return scp:get('lastRCConfig')
end
---@cast res table
scp:set('lastRCConfig', res)
return res
end
---@return table?
function m.loadLocalConfig(uri, filename)
if not filename then
return nil
end
local scp = scope.getScope(uri)
local path = workspace.getAbsolutePath(uri, filename)
if not path then
scp:set('lastLocalConfig', nil)
scp:set('lastLocalType', nil)
return nil
end
local buf = util.loadFile(path)
if not buf then
--errorMessage(lang.script('CONFIG_LOAD_FAILED', path))
scp:set('lastLocalConfig', nil)
scp:set('lastLocalType', nil)
return nil
end
local firstChar = buf:match '%S'
if firstChar == '{' then
local suc, res = pcall(jsonc.decode_jsonc, buf)
if not suc then
errorMessage(lang.script('CONFIG_LOAD_ERROR', res))
return scp:get('lastLocalConfig')
end
---@cast res table
scp:set('lastLocalConfig', res)
scp:set('lastLocalType', 'json')
return res
else
local suc, res = pcall(function ()
return assert(load(buf, '@' .. path, 't'))()
end)
if not suc then
errorMessage(lang.script('CONFIG_LOAD_ERROR', res))
scp:set('lastLocalConfig', res)
end
scp:set('lastLocalConfig', res)
scp:set('lastLocalType', 'lua')
return res
end
end
---@async
---@param uri? uri
---@return table?
function m.loadClientConfig(uri)
local configs = proto.awaitRequest('workspace/configuration', {
items = {
{
scopeUri = uri,
section = 'Lua',
},
{
scopeUri = uri,
section = 'files.associations',
},
{
scopeUri = uri,
section = 'files.exclude',
},
{
scopeUri = uri,
section = 'editor.semanticHighlighting.enabled',
},
{
scopeUri = uri,
section = 'editor.acceptSuggestionOnEnter',
},
},
})
if not configs or not configs[1] then
log.warn('No config?', inspect(configs))
return nil
end
local newConfig = {
['Lua'] = configs[1],
['files.associations'] = configs[2],
['files.exclude'] = configs[3],
['editor.semanticHighlighting.enabled'] = configs[4],
['editor.acceptSuggestionOnEnter'] = configs[5],
}
return newConfig
end
return m

View File

@@ -0,0 +1,435 @@
local util = require 'utility'
local define = require 'proto.define'
local diag = require 'proto.diagnostic'
---@class config.unit
---@field caller function
---@field loader function
---@field _checker fun(self: config.unit, value: any): boolean
---@field name string
---@operator shl: config.unit
---@operator shr: config.unit
---@operator call: config.unit
local mt = {}
mt.__index = mt
function mt:__call(...)
self:caller(...)
return self
end
function mt:__shr(default)
self.default = default
self.hasDefault = true
return self
end
function mt:__shl(enums)
self.enums = enums
return self
end
function mt:checker(v)
if self.enums then
local ok
for _, enum in ipairs(self.enums) do
if util.equal(enum, v) then
ok = true
break
end
end
if not ok then
return false
end
end
return self:_checker(v)
end
local units = {}
local function register(name, default, checker, loader, caller)
units[name] = {
name = name,
default = default,
_checker = checker,
loader = loader,
caller = caller,
}
end
---@class config.master
---@field [string] config.unit
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 = {}
if #value == 0 then
for k in pairs(value) do
if self.sub:checker(k) then
t[#t+1] = self.sub:loader(k)
end
end
else
for _, v in ipairs(value) do
if self.sub:checker(v) then
t[#t+1] = self.sub:loader(v)
end
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)
---@format disable-next
local template = {
['Lua.runtime.version'] = Type.String >> 'Lua 5.4' << {
'Lua 5.1',
'Lua 5.2',
'Lua 5.3',
'Lua 5.4',
'LuaJIT',
},
['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 >> 'require' << {
'_G',
'rawset',
'rawget',
'setmetatable',
'require',
'dofile',
'loadfile',
'pcall',
'xpcall',
'assert',
'error',
'type',
'os.exit',
}
),
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',
['Lua.runtime.unicodeName'] = Type.Boolean,
['Lua.runtime.nonstandardSymbol'] = Type.Array(Type.String << {
'//', '/**/',
'`',
'+=', '-=', '*=', '/=', '%=', '^=', '//=',
'|=', '&=', '<<=', '>>=',
'||', '&&', '!', '!=',
'continue',
}),
['Lua.runtime.plugin'] = Type.Or(Type.String, Type.Array(Type.String)) ,
['Lua.runtime.pluginArgs'] = Type.Or(Type.Array(Type.String), Type.Hash(Type.String, Type.String)),
['Lua.runtime.fileEncoding'] = Type.String >> 'utf8' << {
'utf8',
'ansi',
'utf16le',
'utf16be',
},
['Lua.runtime.builtin'] = Type.Hash(
Type.String << util.getTableKeys(define.BuiltIn, true),
Type.String >> 'default' << {
'default',
'enable',
'disable',
}
)
>> util.deepCopy(define.BuiltIn),
['Lua.diagnostics.enable'] = Type.Boolean >> true,
['Lua.diagnostics.globals'] = Type.Array(Type.String),
['Lua.diagnostics.globalsRegex'] = Type.Array(Type.String),
['Lua.diagnostics.disable'] = Type.Array(Type.String << util.getTableKeys(diag.getDiagAndErrNameMap(), true)),
['Lua.diagnostics.severity'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultNeededFileStatus, true),
Type.String << {
'Error',
'Warning',
'Information',
'Hint',
'Error!',
'Warning!',
'Information!',
'Hint!',
}
)
>> util.deepCopy(define.DiagnosticDefaultSeverity),
['Lua.diagnostics.neededFileStatus'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultNeededFileStatus, true),
Type.String << {
'Any',
'Opened',
'None',
'Any!',
'Opened!',
'None!',
}
)
>> util.deepCopy(define.DiagnosticDefaultNeededFileStatus),
['Lua.diagnostics.groupSeverity'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultGroupSeverity, true),
Type.String << {
'Error',
'Warning',
'Information',
'Hint',
'Fallback',
}
)
>> util.deepCopy(define.DiagnosticDefaultGroupSeverity),
['Lua.diagnostics.groupFileStatus'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultGroupFileStatus, true),
Type.String << {
'Any',
'Opened',
'None',
'Fallback',
}
)
>> util.deepCopy(define.DiagnosticDefaultGroupFileStatus),
['Lua.diagnostics.disableScheme'] = Type.Array(Type.String) >> { 'git' },
['Lua.diagnostics.workspaceEvent'] = Type.String >> 'OnSave' << {
'OnChange',
'OnSave',
'None',
},
['Lua.diagnostics.workspaceDelay'] = Type.Integer >> 3000,
['Lua.diagnostics.workspaceRate'] = Type.Integer >> 100,
['Lua.diagnostics.libraryFiles'] = Type.String >> 'Opened' << {
'Enable',
'Opened',
'Disable',
},
['Lua.diagnostics.ignoredFiles'] = Type.String >> 'Opened' << {
'Enable',
'Opened',
'Disable',
},
['Lua.diagnostics.unusedLocalExclude'] = Type.Array(Type.String),
['Lua.workspace.ignoreDir'] = Type.Array(Type.String) >> {
'.vscode',
},
['Lua.workspace.ignoreSubmodules'] = Type.Boolean >> true,
['Lua.workspace.useGitIgnore'] = Type.Boolean >> true,
['Lua.workspace.maxPreload'] = Type.Integer >> 5000,
['Lua.workspace.preloadFileSize'] = Type.Integer >> 500,
['Lua.workspace.library'] = Type.Array(Type.String),
['Lua.workspace.checkThirdParty'] = Type.Or(Type.String >> 'Ask' << {
'Ask',
'Apply',
'ApplyInMemory',
'Disable',
}, Type.Boolean),
['Lua.workspace.userThirdParty'] = Type.Array(Type.String),
['Lua.completion.enable'] = Type.Boolean >> true,
['Lua.completion.callSnippet'] = Type.String >> 'Disable' << {
'Disable',
'Both',
'Replace',
},
['Lua.completion.keywordSnippet'] = Type.String >> 'Replace' << {
'Disable',
'Both',
'Replace',
},
['Lua.completion.displayContext'] = Type.Integer >> 0,
['Lua.completion.workspaceWord'] = Type.Boolean >> true,
['Lua.completion.showWord'] = Type.String >> 'Fallback' << {
'Enable',
'Fallback',
'Disable',
},
['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 >> 10,
['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' << {
'All',
'Literal',
'Disable',
},
['Lua.hint.await'] = Type.Boolean >> true,
['Lua.hint.awaitPropagate'] = Type.Boolean >> false,
['Lua.hint.arrayIndex'] = Type.String >> 'Auto' << {
'Enable',
'Auto',
'Disable',
},
['Lua.hint.semicolon'] = Type.String >> 'SameLine' << {
'All',
'SameLine',
'Disable',
},
['Lua.window.statusBar'] = Type.Boolean >> true,
['Lua.window.progressBar'] = Type.Boolean >> true,
['Lua.codeLens.enable'] = Type.Boolean >> false,
['Lua.format.enable'] = Type.Boolean >> true,
['Lua.format.defaultConfig'] = Type.Hash(Type.String, Type.String)
>> {},
['Lua.typeFormat.config'] = Type.Hash(Type.String, Type.String)
>> {
format_line = "true",
auto_complete_end = "true",
auto_complete_table_sep = "true"
},
['Lua.spell.dict'] = Type.Array(Type.String),
['Lua.nameStyle.config'] = Type.Hash(Type.String, Type.Or(Type.String, Type.Array(Type.Hash(Type.String, Type.String))))
>> {},
['Lua.misc.parameters'] = Type.Array(Type.String),
['Lua.misc.executablePath'] = Type.String,
['Lua.language.fixIndent'] = Type.Boolean >> true,
['Lua.language.completeAnnotation'] = Type.Boolean >> true,
['Lua.type.castNumberToInteger'] = Type.Boolean >> true,
['Lua.type.weakUnionCheck'] = Type.Boolean >> false,
['Lua.type.weakNilCheck'] = Type.Boolean >> false,
['Lua.type.inferParamType'] = Type.Boolean >> false,
['Lua.type.checkTableShape'] = Type.Boolean >> false,
['Lua.type.inferTableSize'] = Type.Integer >> 10,
['Lua.doc.privateName'] = Type.Array(Type.String),
['Lua.doc.protectedName'] = Type.Array(Type.String),
['Lua.doc.packageName'] = Type.Array(Type.String),
['Lua.doc.regengine'] = Type.String >> 'glob' << {
'glob',
'lua',
},
--testma
["Lua.docScriptPath"] = Type.String,
-- VSCode
["Lua.addonManager.enable"] = Type.Boolean >> true,
["Lua.addonManager.repositoryPath"] = Type.String,
["Lua.addonManager.repositoryBranch"] = Type.String,
['files.associations'] = Type.Hash(Type.String, Type.String),
-- copy from VSCode default
['files.exclude'] = Type.Hash(Type.String, Type.Boolean) >> {
["**/.DS_Store"] = true,
["**/.git"] = true,
["**/.hg"] = true,
["**/.svn"] = true,
["**/CVS"] = true,
["**/Thumbs.db"] = true,
},
['editor.semanticHighlighting.enabled'] = Type.Or(Type.Boolean, Type.String),
['editor.acceptSuggestionOnEnter'] = Type.String >> 'on',
}
return template