diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-01 20:00:22 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-01 20:00:22 +0800 |
commit | 71e3ff51d3fb21f3e78a3948809ce4ae92613de2 (patch) | |
tree | 936752e4377a48281cd4b1752b53bcda1352d0bb /script | |
parent | 8077e3e08f2dd799ef9b5335005f1bf85d6340cd (diff) | |
download | lua-language-server-71e3ff51d3fb21f3e78a3948809ce4ae92613de2.zip |
cleanup
Diffstat (limited to 'script')
-rw-r--r-- | script/config/config.lua | 47 | ||||
-rw-r--r-- | script/config/loader.lua | 2 | ||||
-rw-r--r-- | script/core/completion.lua | 22 | ||||
-rw-r--r-- | script/core/diagnostics/deprecated.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/init.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/lowercase-global.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-global.lua | 4 | ||||
-rw-r--r-- | script/core/hint.lua | 6 | ||||
-rw-r--r-- | script/core/hover/description.lua | 4 | ||||
-rw-r--r-- | script/core/hover/label.lua | 2 | ||||
-rw-r--r-- | script/core/hover/table.lua | 2 | ||||
-rw-r--r-- | script/core/infer.lua | 4 | ||||
-rw-r--r-- | script/files.lua | 20 | ||||
-rw-r--r-- | script/library.lua | 12 | ||||
-rw-r--r-- | script/plugin.lua | 4 | ||||
-rw-r--r-- | script/progress.lua | 4 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 12 | ||||
-rw-r--r-- | script/provider/provider.lua | 16 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 2 | ||||
-rw-r--r-- | script/service/telemetry.lua | 6 | ||||
-rw-r--r-- | script/vm/getDocs.lua | 2 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 34 |
22 files changed, 108 insertions, 111 deletions
diff --git a/script/config/config.lua b/script/config/config.lua index 27ce2e55..c8f848f9 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -143,8 +143,8 @@ end, function (self, ...) end) local Template = { - ['Lua.runtime.verion'] = Type.String >> 'Lua 5.4', - ['Lua.runtime.path'] = Type.String >> { + ['Lua.runtime.version'] = Type.String >> 'Lua 5.4', + ['Lua.runtime.path'] = Type.Array(Type.String) >> { "?.lua", "?/init.lua", "?/?.lua" @@ -199,39 +199,36 @@ local Template = { ['editor.acceptSuggestionOnEnter'] = Type.String >> 'on', } +local config = {} + local m = {} -local function updateConfig(key, value) - local current = m - local strs = {} - for str in key:gmatch('[^%.]+') do - strs[#strs+1] = str +function m.set(key, value) + local unit = Template[key] + if not unit then + return end - for i = 1, #strs - 1 do - local str = strs[i] - if not current[str] then - current[str] = {} - end - current = current[str] + if unit:checker(value) then + config[key] = unit:loader(value) + else + config[key] = unit.default end - local lastStr = strs[#strs] - current[lastStr] = value end -local function pushConfig(key, value) - local config = Template[key] - if not config then - return - end - if config:checker(value) then - updateConfig(key, config:loader(value)) - else - updateConfig(key, config.default) +function m.get(key) + return config[key] +end + +function m.copy() + local t = {} + for k, v in pairs(config) do + t[k] = v end + return t end for key in pairs(Template) do - pushConfig(key) + m.set(key) end return m diff --git a/script/config/loader.lua b/script/config/loader.lua index 4159547e..8310edfe 100644 --- a/script/config/loader.lua +++ b/script/config/loader.lua @@ -3,7 +3,7 @@ local fsu = require 'fs-utility' local json = require 'json' local proto = require 'proto' local lang = require 'language' -local config = require 'config.Lua' +local config = require 'config.config' local function errorMessage(msg) proto.notify('window/showMessage', { diff --git a/script/core/completion.lua b/script/core/completion.lua index 47155e57..01f83242 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -145,7 +145,7 @@ local function buildDetail(source) end local function getSnip(source) - local context = config.Lua.completion.displayContext + local context = config.get 'Lua.completion.displayContext' if context <= 0 then return nil end @@ -187,7 +187,7 @@ local function buildDesc(source) end local function buildFunction(results, source, value, oop, data) - local snipType = config.Lua.completion.callSnippet + local snipType = config.get 'Lua.completion.callSnippet' if snipType == 'Disable' or snipType == 'Both' then results[#results+1] = data end @@ -220,7 +220,7 @@ local function buildInsertRequire(ast, targetUri, stemName) end end local path = furi.decode(targetUri) - local visiblePaths = rpath.getVisiblePath(path, config.Lua.runtime.path, true) + local visiblePaths = rpath.getVisiblePath(path, config.get 'Lua.runtime.path', true) if not visiblePaths or #visiblePaths == 0 then return nil end @@ -311,7 +311,7 @@ local function checkLocal(ast, word, offset, results) end local function checkModule(ast, word, offset, results) - if not config.Lua.completion.autoRequire then + if not config.get 'Lua.completion.autoRequire' then return end local locals = guide.getVisibleLocals(ast.ast, offset) @@ -325,7 +325,7 @@ local function checkModule(ast, word, offset, results) local stemName = fileName:gsub('%..+', '') if not locals[stemName] and not vm.hasGlobalSets(stemName) - and not config.Lua.diagnostics.globals[stemName] + and not config.get 'Lua.diagnostics.globals'[stemName] and stemName:match '^[%a_][%w_]*$' and matchKey(word, stemName) then local targetAst = files.getState(uri) @@ -409,8 +409,8 @@ local function checkFieldFromFieldToIndex(name, parent, word, start, offset) } end else - if config.Lua.runtime.version == 'Lua 5.1' - or config.Lua.runtime.version == 'LuaJIT' then + if config.get 'Lua.runtime.version' == 'Lua 5.1' + or config.get 'Lua.runtime.version' == 'LuaJIT' then textEdit.newText = '_G' .. textEdit.newText else textEdit.newText = '_ENV' .. textEdit.newText @@ -494,7 +494,7 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res goto CONTINUE end local funcLabel - if config.Lua.completion.showParams then + if config.get 'Lua.completion.showParams' then local value = searcher.getObjectValue(src) or src if value.type == 'function' or value.type == 'doc.type.function' then @@ -594,7 +594,7 @@ local function checkCommon(myUri, word, text, offset, results) for _, data in ipairs(keyWordMap) do used[data[1]] = true end - if config.Lua.completion.workspaceWord and #word >= 2 then + if config.get 'Lua.completion.workspaceWord' and #word >= 2 then local myHead = word:sub(1, 2) for uri in files.eachFile() do if #results >= 100 then @@ -681,7 +681,7 @@ local function isInString(ast, offset) end local function checkKeyWord(ast, text, start, offset, word, hasSpace, afterLocal, results) - local snipType = config.Lua.completion.keywordSnippet + local snipType = config.get 'Lua.completion.keywordSnippet' local symbol = lookBackward.findSymbol(text, start - 1) local isExp = symbol == '(' or symbol == ',' or symbol == '=' local info = { @@ -865,7 +865,7 @@ local function checkUri(ast, text, offset, results) goto CONTINUE end local path = workspace.getRelativePath(uri) - local infos = rpath.getVisiblePath(path, config.Lua.runtime.path) + local infos = rpath.getVisiblePath(path, config.get 'Lua.runtime.path') for _, info in ipairs(infos) do if matchKey(literal, info.expect) then if not collect[info.expect] then diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua index 5c2933f9..22bf70c0 100644 --- a/script/core/diagnostics/deprecated.lua +++ b/script/core/diagnostics/deprecated.lua @@ -27,10 +27,10 @@ return function (uri, callback) if not key then return end - if config.Lua.diagnostics.globals[key] then + if config.get 'Lua.diagnostics.globals'[key] then return end - if config.Lua.runtime.special[key] then + if config.get 'Lua.runtime.special'[key] then return end end @@ -75,7 +75,7 @@ return function (uri, callback) end table.sort(versions) if #versions > 0 then - message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.Lua.runtime.version)) + message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.get 'Lua.runtime.version')) end end diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 5a070360..09688f6e 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -20,13 +20,13 @@ table.sort(diagList, function (a, b) end) local function check(uri, name, results) - if config.Lua.diagnostics.disable[name] then + if config.get 'Lua.diagnostics.disable'[name] then return end - local level = config.Lua.diagnostics.severity[name] + local level = config.get 'Lua.diagnostics.severity'[name] or define.DiagnosticDefaultSeverity[name] - local neededFileStatus = config.Lua.diagnostics.neededFileStatus[name] + local neededFileStatus = config.get 'Lua.diagnostics.neededFileStatus'[name] or define.DiagnosticDefaultNeededFileStatus[name] if neededFileStatus == 'None' then diff --git a/script/core/diagnostics/lowercase-global.lua b/script/core/diagnostics/lowercase-global.lua index 967a9737..299ac110 100644 --- a/script/core/diagnostics/lowercase-global.lua +++ b/script/core/diagnostics/lowercase-global.lua @@ -24,7 +24,7 @@ return function (uri, callback) end local definedGlobal = {} - for name in pairs(config.Lua.diagnostics.globals) do + for name in pairs(config.get 'Lua.diagnostics.globals') do definedGlobal[name] = true end diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua index 01caa7d2..c7ddeac2 100644 --- a/script/core/diagnostics/undefined-global.lua +++ b/script/core/diagnostics/undefined-global.lua @@ -25,10 +25,10 @@ return function (uri, callback) if not key then return end - if config.Lua.diagnostics.globals[key] then + if config.get 'Lua.diagnostics.globals'[key] then return end - if config.Lua.runtime.special[key] then + if config.get 'Lua.runtime.special'[key] then return end local node = src.node diff --git a/script/core/hint.lua b/script/core/hint.lua index 857ae510..a2864709 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -29,11 +29,11 @@ local function typeHint(uri, edits, start, finish) return end if source.parent.type == 'funcargs' then - if not config.Lua.hint.paramType then + if not config.get 'Lua.hint.paramType' then return end else - if not config.Lua.hint.setType then + if not config.get 'Lua.hint.setType' then return end end @@ -96,7 +96,7 @@ local function hasLiteralArgInCall(call) end local function paramName(uri, edits, start, finish) - if not config.Lua.hint.paramName then + if not config.get 'Lua.hint.paramName' then return end local ast = files.getState(uri) diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 431fa619..5bb86603 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -59,11 +59,11 @@ end local function asStringView(source, literal) -- 内部包含转义符? local rawLen = source.finish - source.start - 2 * #source[2] + 1 - if config.Lua.hover.viewString + if config.get 'Lua.hover.viewString' and (source[2] == '"' or source[2] == "'") and rawLen > #literal then local view = literal - local max = config.Lua.hover.viewStringMax + local max = config.get 'Lua.hover.viewStringMax' if #view > max then view = view:sub(1, max) .. '...' end diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index cda2af65..15cd2af9 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -157,7 +157,7 @@ local function formatNumber(n) end local function asNumber(source) - if not config.Lua.hover.viewNumber then + if not config.get 'Lua.hover.viewNumber' then return nil end local num = source[1] diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua index f064c99a..00f11659 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -91,7 +91,7 @@ local function getKeyMap(fields) end return function (source) - local maxFields = config.Lua.hover.previewFields + local maxFields = config.get 'Lua.hover.previewFields' if maxFields <= 0 then return 'table' end diff --git a/script/core/infer.lua b/script/core/infer.lua index 06839dd2..ef3076b7 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -217,7 +217,7 @@ local function bindClassOrType(source) end local function cleanInfers(infers) - local version = config.Lua.runtime.version + local version = config.get 'Lua.runtime.version' local enableInteger = version == 'Lua 5.3' or version == 'Lua 5.4' infers['unknown'] = nil if infers['any'] and infers['nil'] then @@ -305,7 +305,7 @@ function m.viewInfers(infers) return sa < sb end end) - local limit = config.Lua.hover.enumsLimit + local limit = config.get 'Lua.hover.enumsLimit' if limit < 0 then limit = 0 end diff --git a/script/files.lua b/script/files.lua index 494bdb9f..63499fe2 100644 --- a/script/files.lua +++ b/script/files.lua @@ -164,7 +164,7 @@ function m.setText(uri, text, isTrust, instance) return end if not isTrust and unicode then - if config.Lua.runtime.fileEncoding == 'ansi' then + if config.get 'Lua.runtime.fileEncoding' == 'ansi' then text = unicode.a2u(text) end end @@ -393,7 +393,7 @@ end function m.compileState(uri, text) local ws = require 'workspace' - if not m.isOpen(uri) and #text >= config.Lua.workspace.preloadFileSize * 1000 then + if not m.isOpen(uri) and #text >= config.get 'Lua.workspace.preloadFileSize' * 1000 then if not m.notifyCache['preloadFileSize'] then m.notifyCache['preloadFileSize'] = {} m.notifyCache['skipLargeFileCount'] = 0 @@ -406,7 +406,7 @@ function m.compileState(uri, text) type = 3, message = lang.script('WORKSPACE_SKIP_LARGE_FILE' , ws.getRelativePath(m.getOriginUri(uri)) - , config.Lua.workspace.preloadFileSize + , config.get 'Lua.workspace.preloadFileSize' , #text / 1000 ), }) @@ -419,11 +419,11 @@ function m.compileState(uri, text) local clock = os.clock() local state, err = parser:compile(text , 'lua' - , config.Lua.runtime.version + , config.get 'Lua.runtime.version' , { - special = config.Lua.runtime.special, - unicodeName = config.Lua.runtime.unicodeName, - nonstandardSymbol = config.Lua.runtime.nonstandardSymbol, + special = config.get 'Lua.runtime.special', + unicodeName = config.get 'Lua.runtime.unicodeName', + nonstandardSymbol = config.get 'Lua.runtime.nonstandardSymbol', delay = await.delay, } ) @@ -764,12 +764,12 @@ end --- 获取文件关联 function m.getAssoc() - if m.assocVersion == config.version then + if m.assocVersion == config.get 'version' then return m.assocMatcher end - m.assocVersion = config.version + m.assocVersion = config.get 'version' local patt = {} - for k, v in pairs(config.other.associations) do + for k, v in pairs(config.get 'other.associations') do if m.eq(v, 'lua') then patt[#patt+1] = k end diff --git a/script/library.lua b/script/library.lua index c4308289..985cd1e8 100644 --- a/script/library.lua +++ b/script/library.lua @@ -10,7 +10,7 @@ local define = require "proto.define" local m = {} local function getDocFormater() - local version = config.Lua.runtime.version + local version = config.get 'Lua.runtime.version' if client.isVSCode() then if version == 'Lua 5.1' then return 'HOVER_NATIVE_DOCUMENT_LUA51' @@ -94,11 +94,11 @@ local function compileSingleMetaDoc(script, metaLang, status) middleBuf[#middleBuf+1] = ('PUSH [===[%s]===]'):format(script:sub(last)) local middleScript = table.concat(middleBuf, '\n') local version, jit - if config.Lua.runtime.version == 'LuaJIT' then + if config.get 'Lua.runtime.version' == 'LuaJIT' then version = 5.1 jit = true else - version = tonumber(config.Lua.runtime.version:sub(-3)) + version = tonumber(config.get 'Lua.runtime.version':sub(-3)) jit = false end @@ -194,8 +194,8 @@ end local function compileMetaDoc() local langID = lang.id - local version = config.Lua.runtime.version - local metaPath = fs.path(METAPATH) / config.Lua.runtime.meta:gsub('%$%{(.-)%}', { + local version = config.get 'Lua.runtime.version' + local metaPath = fs.path(METAPATH) / config.get 'Lua.runtime.meta':gsub('%$%{(.-)%}', { version = version, language = langID, }) @@ -212,7 +212,7 @@ local function compileMetaDoc() local out = fsu.dummyFS() local templateDir = ROOT / 'meta' / 'template' for libName, status in pairs(define.BuiltIn) do - status = config.Lua.runtime.builtin[libName] or status + status = config.get 'Lua.runtime.builtin'[libName] or status if status == 'disable' then goto CONTINUE end diff --git a/script/plugin.lua b/script/plugin.lua index a3eaf92b..af86cea5 100644 --- a/script/plugin.lua +++ b/script/plugin.lua @@ -49,11 +49,11 @@ function m.init() end end - if not config.Lua.runtime.plugin or config.Lua.runtime.plugin == '' then + if not config.get 'Lua.runtime.plugin' or config.get 'Lua.runtime.plugin' == '' then return end - local pluginPath = fs.path(config.Lua.runtime.plugin) + local pluginPath = fs.path(config.get 'Lua.runtime.plugin') if pluginPath:is_relative() then if not ws.path then return diff --git a/script/progress.lua b/script/progress.lua index c16ddd3d..8ae5e9e0 100644 --- a/script/progress.lua +++ b/script/progress.lua @@ -83,7 +83,7 @@ function mt:_update() and self._clock + self._delay <= os.clock() then self._updated = os.clock() self._dirty = false - if not config.Lua.window.progressBar then + if not config.get 'Lua.window.progressBar' then return end proto.request('window/workDoneProgress/create', { @@ -106,7 +106,7 @@ function mt:_update() if not self._showed then return end - if not config.Lua.window.progressBar then + if not config.get 'Lua.window.progressBar' then self:remove() return end diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index d461ed3c..88fbbc4e 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -26,7 +26,7 @@ local function buildSyntaxError(uri, err) local message = lang.script('PARSER_'..err.type, err.info) if err.version then - local version = err.info and err.info.version or config.Lua.runtime.version + local version = err.info and err.info.version or config.get 'Lua.runtime.version' message = message .. ('(%s)'):format(lang.script('DIAG_NEED_VERSION' , concat(err.version, '/') , version @@ -151,7 +151,7 @@ function m.syntaxErrors(uri, ast) local results = {} for _, err in ipairs(ast.errs) do - if not config.Lua.diagnostics.disable[err.type:lower():gsub('_', '-')] then + if not config.get 'Lua.diagnostics.disable'[err.type:lower():gsub('_', '-')] then results[#results+1] = buildSyntaxError(uri, err) end end @@ -179,7 +179,7 @@ function m.diagnostics(uri, diags) end function m.doDiagnostic(uri) - if not config.Lua.diagnostics.enable then + if not config.get 'Lua.diagnostics.enable' then return end uri = files.asKey(uri) @@ -302,14 +302,14 @@ local function askForDisable() end function m.diagnosticsAll() - if not config.Lua.diagnostics.enable then + if not config.get 'Lua.diagnostics.enable' then m.clearAll() return end if not m._start then return end - local delay = config.Lua.diagnostics.workspaceDelay / 1000 + local delay = config.get 'Lua.diagnostics.workspaceDelay' / 1000 if delay < 0 then return end @@ -361,7 +361,7 @@ function m.checkWorkspaceDiag() if not await.hasID 'diagnosticsAll' then return end - local speedRate = config.Lua.diagnostics.workspaceRate + local speedRate = config.get 'Lua.diagnostics.workspaceRate' if speedRate <= 0 or speedRate >= 100 then return end diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 33404886..54e3d2f4 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -61,11 +61,11 @@ local function updateConfig() acceptSuggestionOnEnter = configs[5], } - local oldConfig = util.deepCopy(config.Lua) - local oldOther = util.deepCopy(config.other) - config.setConfig(updated, other) - local newConfig = config.Lua - local newOther = config.other + local oldConfig = util.deepCopy(config.get 'Lua') + local oldOther = util.deepCopy(config.get 'other') + config.get 'setConfig'(updated, other) + local newConfig = config.get 'Lua' + local newOther = config.get 'other' if not util.equal(oldConfig.runtime, newConfig.runtime) then library.init() @@ -474,7 +474,7 @@ proto.on('textDocument/completion', function (params) return nil end local triggerCharacter = params.context and params.context.triggerCharacter - if config.other.acceptSuggestionOnEnter ~= 'off' then + if config.get 'other.acceptSuggestionOnEnter' ~= 'off' then if triggerCharacter == '\n' or triggerCharacter == '{' or triggerCharacter == ',' then @@ -598,7 +598,7 @@ proto.on('completionItem/resolve', function (item) end) proto.on('textDocument/signatureHelp', function (params) - if not config.Lua.signatureHelp.enable then + if not config.get 'Lua.signatureHelp.enable' then return nil end workspace.awaitReady() @@ -895,7 +895,7 @@ do local function updateHint(uri) local awaitID = 'hint:' .. uri await.close(awaitID) - if not config.Lua.hint.enable then + if not config.get 'Lua.hint.enable' then return end await.setID(awaitID) diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index bee31eaa..57c61afd 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -47,7 +47,7 @@ local function enable() }, } }) - if config.other.semantic == 'configuredByTheme' and not dontShowAgain then + if config.get 'other.semantic' == 'configuredByTheme' and not dontShowAgain then proto.request('window/showMessageRequest', { type = define.MessageType.Info, message = lang.script.WINDOW_CHECK_SEMANTIC, diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua index 19fe86f1..f3a3cf12 100644 --- a/script/service/telemetry.lua +++ b/script/service/telemetry.lua @@ -65,7 +65,7 @@ end timer.wait(5, function () timer.loop(300, function () - if not config.Lua.telemetry.enable then + if not config.get 'Lua.telemetry.enable' then return end local suc, link = pcall(net.connect, 'tcp', 'moe-moe.love', 11577) @@ -83,7 +83,7 @@ timer.wait(5, function () end end)() timer.loop(1, function () - if not config.Lua.telemetry.enable then + if not config.get 'Lua.telemetry.enable' then return end net.update() @@ -93,7 +93,7 @@ end) local m = {} function m.updateConfig() - if config.Lua.telemetry.enable ~= nil then + if config.get 'Lua.telemetry.enable' ~= nil then return end if m.hasShowedMessage then diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index dd21c965..e8fefb7a 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -135,7 +135,7 @@ local function isDeprecated(value) return true elseif doc.type == 'doc.version' then local valids = vm.getValidVersions(doc) - if not valids[config.Lua.runtime.version] then + if not valids[config.get 'Lua.runtime.version'] then value._deprecated = true return true end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index ae3af6d4..8137a507 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -76,20 +76,20 @@ function m.getNativeMatcher() end local pattern = {} - -- config.workspace.ignoreDir - for path in pairs(config.Lua.workspace.ignoreDir) do + -- config.get 'workspace.ignoreDir' + for path in pairs(config.get 'Lua.workspace.ignoreDir') do log.info('Ignore directory:', path) pattern[#pattern+1] = path end - -- config.files.exclude - for path, ignore in pairs(config.other.exclude) do + -- config.get 'files.exclude' + for path, ignore in pairs(config.get 'other.exclude') do if ignore then log.info('Ignore by exclude:', path) pattern[#pattern+1] = path end end - -- config.workspace.ignoreSubmodules - if config.Lua.workspace.ignoreSubmodules then + -- config.get 'workspace.ignoreSubmodules' + if config.get 'Lua.workspace.ignoreSubmodules' then local buf = pub.awaitTask('loadFile', furi.encode(m.path .. '/.gitmodules')) if buf then for path in buf:gmatch('path = ([^\r\n]+)') do @@ -98,8 +98,8 @@ function m.getNativeMatcher() end end end - -- config.workspace.useGitIgnore - if config.Lua.workspace.useGitIgnore then + -- config.get 'workspace.useGitIgnore' + if config.get 'Lua.workspace.useGitIgnore' then local buf = pub.awaitTask('loadFile', furi.encode(m.path .. '/.gitignore')) if buf then for line in buf:gmatch '[^\r\n]+' do @@ -119,8 +119,8 @@ function m.getNativeMatcher() end end end - -- config.workspace.library - for path in pairs(config.Lua.workspace.library) do + -- config.get 'workspace.library' + for path in pairs(config.get 'Lua.workspace.library') do path = path:gsub('${(.-)}', { meta = (ROOT / 'meta' / '3rd'):string(), }) @@ -131,7 +131,7 @@ function m.getNativeMatcher() m.nativeMatcher = glob.gitignore(pattern, m.matchOption, globInteferFace) m.nativeMatcher:setOption('root', m.path) - m.nativeVersion = config.version + m.nativeVersion = config.get 'version' return m.nativeMatcher end @@ -142,7 +142,7 @@ function m.getLibraryMatchers() end local librarys = {} - for path in pairs(config.Lua.workspace.library) do + for path in pairs(config.get 'Lua.workspace.library') do path = path:gsub('${(.-)}', { meta = (ROOT / 'meta' / '3rd'):string(), }) @@ -165,7 +165,7 @@ function m.getLibraryMatchers() end end - m.libraryVersion = config.version + m.libraryVersion = config.get 'version' return m.libraryMatchers end @@ -183,12 +183,12 @@ local function loadFileFactory(root, progressData, isLibrary) return function (path) local uri = furi.encode(path) if files.isLua(uri) then - if not isLibrary and progressData.preload >= config.Lua.workspace.maxPreload then + if not isLibrary and progressData.preload >= config.get 'Lua.workspace.maxPreload' then if not m.hasHitMaxPreload then m.hasHitMaxPreload = true proto.request('window/showMessageRequest', { type = define.MessageType.Info, - message = lang.script('MWS_MAX_PRELOAD', config.Lua.workspace.maxPreload), + message = lang.script('MWS_MAX_PRELOAD', config.get 'Lua.workspace.maxPreload'), actions = { { title = lang.script.WINDOW_INCREASE_UPPER_LIMIT, @@ -207,7 +207,7 @@ local function loadFileFactory(root, progressData, isLibrary) data = { key = 'Lua.workspace.maxPreload', action = 'set', - value = config.Lua.workspace.maxPreload + math.max(1000, config.Lua.workspace.maxPreload), + value = config.get 'Lua.workspace.maxPreload' + math.max(1000, config.get 'Lua.workspace.maxPreload'), } }) end @@ -415,7 +415,7 @@ function m.findUrisByRequirePath(path) local input = path:gsub('%.', '/') :gsub('%%', '%%%%') - for _, luapath in ipairs(config.Lua.runtime.path) do + for _, luapath in ipairs(config.get 'Lua.runtime.path') do local part = m.normalize(luapath:gsub('%?', input)) local uris, posts = m.findUrisByFilePath(part) for _, uri in ipairs(uris) do |