diff options
Diffstat (limited to 'script')
26 files changed, 123 insertions, 122 deletions
diff --git a/script/config/config.lua b/script/config/config.lua index 2feb9868..542bdcf2 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -221,14 +221,14 @@ local rawConfig = {} local m = {} m.watchList = {} -local function update(key, value, raw) +local function update(uri, key, value, raw) local oldValue = config[key] config[key] = value rawConfig[key] = raw m.event(key, value, oldValue) end -function m.set(key, value) +function m.set(uri, key, value) local unit = Template[key] if not unit then return false @@ -237,14 +237,14 @@ function m.set(key, value) return false end if unit:checker(value) then - update(key, unit:loader(value), value) + update(uri, key, unit:loader(value), value) else - update(key, unit.default, unit.default) + update(uri, key, unit.default, unit.default) end return true end -function m.add(key, value) +function m.add(uri, key, value) local unit = Template[key] if not unit then return false @@ -262,12 +262,12 @@ function m.add(key, value) end copyed[#copyed+1] = value if unit:checker(copyed) then - update(key, unit:loader(copyed), copyed) + update(uri, key, unit:loader(copyed), copyed) end return true end -function m.prop(key, prop, value) +function m.prop(uri, key, prop, value) local unit = Template[key] if not unit then return false @@ -285,12 +285,12 @@ function m.prop(key, prop, value) end copyed[prop] = value if unit:checker(copyed) then - update(key, unit:loader(copyed), copyed) + update(uri, key, unit:loader(copyed), copyed) end return true end -function m.get(key) +function m.get(uri, key) return config[key] end @@ -320,7 +320,7 @@ function m.dump() return dump end -function m.update(new) +function m.update(uri, new) local function expand(t, left) for key, value in pairs(t) do local fullKey = key @@ -328,9 +328,9 @@ function m.update(new) fullKey = left .. '.' .. key end if Template[fullKey] then - m.set(fullKey, value) + m.set(uri, fullKey, value) elseif Template['Lua.' .. fullKey] then - m.set('Lua.' .. fullKey, value) + m.set(uri, 'Lua.' .. fullKey, value) elseif type(value) == 'table' then expand(value, fullKey) end @@ -371,7 +371,7 @@ function m.init() end m.inited = true for key, unit in pairs(Template) do - m.set(key, unit.default) + m.set(nil, key, unit.default) end end diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index ba2b0efc..ee3bbf0c 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -180,7 +180,7 @@ local function buildDetail(source) end local function getSnip(source) - local context = config.get 'Lua.completion.displayContext' + local context = config.get(nil, 'Lua.completion.displayContext') if context <= 0 then return nil end @@ -222,7 +222,7 @@ local function buildDesc(source) end local function buildFunction(results, source, value, oop, data) - local snipType = config.get 'Lua.completion.callSnippet' + local snipType = config.get(nil, 'Lua.completion.callSnippet') if snipType == 'Disable' or snipType == 'Both' then results[#results+1] = data end @@ -324,7 +324,7 @@ local function checkLocal(state, word, position, results) end local function checkModule(state, word, position, results) - if not config.get 'Lua.completion.autoRequire' then + if not config.get(nil, 'Lua.completion.autoRequire') then return end local locals = guide.getVisibleLocals(state.ast, position) @@ -337,7 +337,7 @@ local function checkModule(state, word, position, results) local stemName = fileName:gsub('%..+', '') if not locals[stemName] and not vm.hasGlobalSets(stemName) - and not config.get 'Lua.diagnostics.globals'[stemName] + and not config.get(nil, 'Lua.diagnostics.globals')[stemName] and stemName:match '^[%a_][%w_]*$' and matchKey(word, stemName) then local targetState = files.getState(uri) @@ -448,8 +448,8 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP } end else - if config.get 'Lua.runtime.version' == 'lua 5.1' - or config.get 'Lua.runtime.version' == 'luaJIT' then + if config.get(nil, 'Lua.runtime.version') == 'lua 5.1' + or config.get(nil, 'Lua.runtime.version') == 'luaJIT' then textEdit.newText = '_G' .. textEdit.newText else textEdit.newText = '_ENV' .. textEdit.newText @@ -536,7 +536,7 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o goto CONTINUE end local funcLabel - if config.get 'Lua.completion.showParams' then + if config.get(nil, 'Lua.completion.showParams') then local value = searcher.getObjectValue(src) or src if value.type == 'function' or value.type == 'doc.type.function' then @@ -630,7 +630,7 @@ end local function checkCommon(state, word, position, results) local myUri = state.uri - local showWord = config.get 'Lua.completion.showWord' + local showWord = config.get(nil, 'Lua.completion.showWord') if showWord == 'Disable' then return end @@ -645,7 +645,7 @@ local function checkCommon(state, word, position, results) for _, data in ipairs(keyWordMap) do used[data[1]] = true end - if config.get 'Lua.completion.workspaceWord' and #word >= 2 then + if config.get(nil, 'Lua.completion.workspaceWord') and #word >= 2 then results.complete = true local myHead = word:sub(1, 2) for uri in files.eachFile() do @@ -720,7 +720,7 @@ end local function checkKeyWord(state, start, position, word, hasSpace, afterLocal, results) local text = state.lua - local snipType = config.get 'Lua.completion.keywordSnippet' + local snipType = config.get(nil, 'Lua.completion.keywordSnippet') local symbol = lookBackward.findSymbol(text, guide.positionToOffset(state, start)) local isExp = symbol == '(' or symbol == ',' or symbol == '=' local info = { diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua index 9ad20965..08b3feac 100644 --- a/script/core/completion/postfix.lua +++ b/script/core/completion/postfix.lua @@ -277,7 +277,7 @@ return function (state, position, results) offset = newOffset - 1 end local symbol = text:sub(offset, offset) - if symbol == config.get 'Lua.completion.postfix' then + if symbol == config.get(nil, 'Lua.completion.postfix') then local wordPosition = guide.offsetToPosition(state, offset - 1) checkPostFix(state, word or '', wordPosition, position, results) return symbol ~= '.' and symbol ~= ':' diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua index e9a1fef7..5fe36c42 100644 --- a/script/core/diagnostics/deprecated.lua +++ b/script/core/diagnostics/deprecated.lua @@ -23,10 +23,10 @@ return function (uri, callback) if not key then return end - if config.get 'Lua.diagnostics.globals'[key] then + if config.get(nil, 'Lua.diagnostics.globals')[key] then return end - if config.get 'Lua.runtime.special'[key] then + if config.get(nil, 'Lua.runtime.special')[key] then return end end @@ -83,7 +83,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.get 'Lua.runtime.version')) + message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.get(nil, 'Lua.runtime.version'))) end end cache[id] = { diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 4950900b..2a21302b 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.get 'Lua.diagnostics.disable'[name] then + if config.get(nil, 'Lua.diagnostics.disable')[name] then return end - local level = config.get 'Lua.diagnostics.severity'[name] + local level = config.get(nil, 'Lua.diagnostics.severity')[name] or define.DiagnosticDefaultSeverity[name] - local neededFileStatus = config.get 'Lua.diagnostics.neededFileStatus'[name] + local neededFileStatus = config.get(nil, '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 299ac110..bd301c7f 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.get 'Lua.diagnostics.globals') do + for name in pairs(config.get(nil, '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 48c8a226..41a50d99 100644 --- a/script/core/diagnostics/undefined-global.lua +++ b/script/core/diagnostics/undefined-global.lua @@ -27,10 +27,10 @@ return function (uri, callback) if not key then return end - if config.get 'Lua.diagnostics.globals'[key] then + if config.get(nil, 'Lua.diagnostics.globals')[key] then return end - if config.get 'Lua.runtime.special'[key] then + if config.get(nil, 'Lua.runtime.special')[key] then return end local node = src.node diff --git a/script/core/hint.lua b/script/core/hint.lua index 42390443..b3aec88e 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -32,11 +32,11 @@ local function typeHint(uri, results, start, finish) return end if source.parent.type == 'funcargs' then - if not config.get 'Lua.hint.paramType' then + if not config.get(nil, 'Lua.hint.paramType') then return end else - if not config.get 'Lua.hint.setType' then + if not config.get(nil, 'Lua.hint.setType') then return end end @@ -99,7 +99,7 @@ end ---@async local function paramName(uri, results, start, finish) - local paramConfig = config.get 'Lua.hint.paramName' + local paramConfig = config.get(nil, 'Lua.hint.paramName') if not paramConfig or paramConfig == 'None' then return end @@ -162,7 +162,7 @@ end ---@async local function awaitHint(uri, results, start, finish) - local awaitConfig = config.get 'Lua.hint.await' + local awaitConfig = config.get(nil, 'Lua.hint.await') if not awaitConfig then return end diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 2945d47f..51027aed 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -64,11 +64,11 @@ end local function asStringView(source, literal) -- 内部包含转义符? local rawLen = source.finish - source.start - 2 * #source[2] + 1 - if config.get 'Lua.hover.viewString' + if config.get(nil, 'Lua.hover.viewString') and (source[2] == '"' or source[2] == "'") and rawLen > #literal then local view = literal - local max = config.get 'Lua.hover.viewStringMax' + local max = config.get(nil, '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 0bb4fe89..f797d520 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -167,7 +167,7 @@ local function formatNumber(n) end local function asNumber(source) - if not config.get 'Lua.hover.viewNumber' then + if not config.get(nil, '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 285d5c02..3785d479 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -136,7 +136,7 @@ end ---@async return function (source) - local maxFields = config.get 'Lua.hover.previewFields' + local maxFields = config.get(nil, 'Lua.hover.previewFields') if maxFields <= 0 then return 'table' end diff --git a/script/core/infer.lua b/script/core/infer.lua index 8da35289..a17d4faa 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -232,7 +232,7 @@ local function bindClassOrType(source) end local function cleanInfers(infers) - local version = config.get 'Lua.runtime.version' + local version = config.get(nil, 'Lua.runtime.version') local enableInteger = version == 'Lua 5.3' or version == 'Lua 5.4' infers['unknown'] = nil if infers['number'] then @@ -297,7 +297,7 @@ function m.viewInfers(infers) return sa < sb end end) - local limit = config.get 'Lua.hover.enumsLimit' + local limit = config.get(nil, 'Lua.hover.enumsLimit') if limit < 0 then limit = 0 end diff --git a/script/core/noder.lua b/script/core/noder.lua index bc2efa70..60dc15e6 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -494,7 +494,7 @@ local function getNodeKey(source) if methodNode then return getNodeKey(methodNode) end - if config.get 'Lua.IntelliSense.traceFieldInject' then + if config.get(nil, 'Lua.IntelliSense.traceFieldInject') then local localValueID = getLocalValueID(source) if localValueID then return localValueID @@ -764,7 +764,7 @@ local function bindValue(noders, source, id) local bindDocs = source.bindDocs if source.type == 'getlocal' or source.type == 'setlocal' then - if not config.get 'Lua.IntelliSense.traceLocalSet' then + if not config.get(nil, 'Lua.IntelliSense.traceLocalSet') then return end bindDocs = source.node.bindDocs @@ -779,7 +779,7 @@ local function bindValue(noders, source, id) end -- x = y : x -> y pushForward(noders, id, valueID, INFO_REJECT_SET) - if not config.get 'Lua.IntelliSense.traceBeSetted' + if not config.get(nil, 'Lua.IntelliSense.traceBeSetted') and source.type ~= 'local' then return end @@ -1304,7 +1304,7 @@ compileNodeMap = util.switch() , index ) pushForward(noders, returnID, getID(rtnObj)) - if config.get 'Lua.IntelliSense.traceReturn' then + if config.get(nil, 'Lua.IntelliSense.traceReturn') then pushBackward(noders, getID(rtnObj), returnID, INFO_DEEP_AND_DONT_CROSS) end end diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 8389cbb4..291819f2 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -9,7 +9,7 @@ local converter = require 'proto.converter' local infer = require 'core.infer' local config = require 'config' -local isEnhanced = config.get 'Lua.color.mode' == 'SemanticEnhanced' +local isEnhanced = config.get(nil, 'Lua.color.mode') == 'SemanticEnhanced' local Care = {} Care['getglobal'] = function (source, results) diff --git a/script/files.lua b/script/files.lua index d5344847..00e76623 100644 --- a/script/files.lua +++ b/script/files.lua @@ -174,7 +174,7 @@ function m.setText(uri, text, isTrust, version) return end if not isTrust then - local encoding = config.get 'Lua.runtime.fileEncoding' + local encoding = config.get(nil, 'Lua.runtime.fileEncoding') text = encoder.decode(encoding, text) end if file.originText == text then @@ -452,7 +452,7 @@ function m.compileState(uri, text) local client = require 'client' if not m.isOpen(uri) and not m.isLibrary(uri) - and #text >= config.get 'Lua.workspace.preloadFileSize' * 1000 then + and #text >= config.get(nil, 'Lua.workspace.preloadFileSize') * 1000 then if not m.notifyCache['preloadFileSize'] then m.notifyCache['preloadFileSize'] = {} m.notifyCache['skipLargeFileCount'] = 0 @@ -462,7 +462,7 @@ function m.compileState(uri, text) m.notifyCache['skipLargeFileCount'] = m.notifyCache['skipLargeFileCount'] + 1 local message = lang.script('WORKSPACE_SKIP_LARGE_FILE' , ws.getRelativePath(uri) - , config.get 'Lua.workspace.preloadFileSize' + , config.get(nil, 'Lua.workspace.preloadFileSize') , #text / 1000 ) if m.notifyCache['skipLargeFileCount'] <= 1 then @@ -478,11 +478,11 @@ function m.compileState(uri, text) local clock = os.clock() local state, err = parser.compile(text , 'Lua' - , config.get 'Lua.runtime.version' + , config.get(nil, 'Lua.runtime.version') , { - special = config.get 'Lua.runtime.special', - unicodeName = config.get 'Lua.runtime.unicodeName', - nonstandardSymbol = config.get 'Lua.runtime.nonstandardSymbol', + special = config.get(nil, 'Lua.runtime.special'), + unicodeName = config.get(nil, 'Lua.runtime.unicodeName'), + nonstandardSymbol = config.get(nil, 'Lua.runtime.nonstandardSymbol'), } ) local passed = os.clock() - clock @@ -634,12 +634,12 @@ end --- 获取文件关联 function m.getAssoc() - if m.assocVersion == config.get 'version' then + if m.assocVersion == config.get(nil, 'version') then return m.assocMatcher end - m.assocVersion = config.get 'version' + m.assocVersion = config.get(nil, 'version') local patt = {} - for k, v in pairs(config.get 'files.associations') do + for k, v in pairs(config.get(nil, 'files.associations')) do if v == 'lua' then patt[#patt+1] = k end diff --git a/script/library.lua b/script/library.lua index 81242a91..ef62ceab 100644 --- a/script/library.lua +++ b/script/library.lua @@ -15,7 +15,7 @@ local encoder = require 'encoder' local m = {} local function getDocFormater() - local version = config.get 'Lua.runtime.version' + local version = config.get(nil, 'Lua.runtime.version') if client.isVSCode() then if version == 'Lua 5.1' then return 'HOVER_NATIVE_DOCUMENT_LUA51' @@ -99,11 +99,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.get 'Lua.runtime.version' == 'LuaJIT' then + if config.get(nil, 'Lua.runtime.version') == 'LuaJIT' then version = 5.1 jit = true else - version = tonumber(config.get 'Lua.runtime.version':sub(-3)) + version = tonumber(config.get(nil, 'Lua.runtime.version'):sub(-3)) jit = false end @@ -202,9 +202,9 @@ local function initBuiltIn() return end local langID = lang.id - local version = config.get 'Lua.runtime.version' - local encoding = config.get 'Lua.runtime.fileEncoding' - local metaPath = fs.path(METAPATH) / config.get 'Lua.runtime.meta':gsub('%$%{(.-)%}', { + local version = config.get(nil, 'Lua.runtime.version') + local encoding = config.get(nil, 'Lua.runtime.fileEncoding') + local metaPath = fs.path(METAPATH) / config.get(nil, 'Lua.runtime.meta'):gsub('%$%{(.-)%}', { version = version, language = langID, encoding = encoding, @@ -227,7 +227,7 @@ local function initBuiltIn() local out = fsu.dummyFS() local templateDir = ROOT / 'meta' / 'template' for libName, status in pairs(define.BuiltIn) do - status = config.get 'Lua.runtime.builtin'[libName] or status + status = config.get(nil, 'Lua.runtime.builtin')[libName] or status if status == 'disable' then goto CONTINUE end @@ -308,7 +308,7 @@ end local function load3rdConfig() local configs = {} load3rdConfigInDir(innerThirdDir, configs, true) - local thirdDirs = config.get 'Lua.workspace.userThirdParty' + local thirdDirs = config.get(nil, 'Lua.workspace.userThirdParty') for _, thirdDir in ipairs(thirdDirs) do load3rdConfigInDir(fs.path(thirdDir), configs) end @@ -450,7 +450,7 @@ local function check3rd(uri) if hasAsked then return end - if not config.get 'Lua.workspace.checkThirdParty' then + if not config.get(nil, 'Lua.workspace.checkThirdParty') then return end if thirdConfigs == nil then diff --git a/script/plugin.lua b/script/plugin.lua index f56dc9f9..88c4578f 100644 --- a/script/plugin.lua +++ b/script/plugin.lua @@ -84,7 +84,7 @@ function m.init() local ws = require 'workspace' m.interface = {} - local pluginPath = ws.getAbsolutePath(config.get 'Lua.runtime.plugin') + local pluginPath = ws.getAbsolutePath(config.get(nil, 'Lua.runtime.plugin')) log.info('plugin path:', pluginPath) if not pluginPath then return diff --git a/script/progress.lua b/script/progress.lua index 8ae5e9e0..d1595cf8 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.get 'Lua.window.progressBar' then + if not config.get(nil, '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.get 'Lua.window.progressBar' then + if not config.get(nil, 'Lua.window.progressBar') then self:remove() return end diff --git a/script/provider/completion.lua b/script/provider/completion.lua index ec31858a..8e529e95 100644 --- a/script/provider/completion.lua +++ b/script/provider/completion.lua @@ -13,7 +13,7 @@ local function allWords() list[#list+1] = c mark[c] = true end - local postfix = config.get 'Lua.completion.postfix' + local postfix = config.get(nil, 'Lua.completion.postfix') if postfix ~= '' and not mark[postfix] then list[#list+1] = postfix mark[postfix] = true @@ -76,7 +76,7 @@ config.watch(function (key, value) end end if key == 'Lua.completion.postfix' then - if config.get 'Lua.completion.enable' then + if config.get(nil, 'Lua.completion.enable') then disable() enable() end diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index ca4bcdb8..5630d44f 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -29,7 +29,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.get 'Lua.runtime.version' + local version = err.info and err.info.version or config.get(nil, 'Lua.runtime.version') message = message .. ('(%s)'):format(lang.script('DIAG_NEED_VERSION' , concat(err.version, '/') , version @@ -159,7 +159,7 @@ function m.syntaxErrors(uri, ast) pcall(function () for _, err in ipairs(ast.errs) do - if not config.get 'Lua.diagnostics.disable'[err.type:lower():gsub('_', '-')] then + if not config.get(nil, 'Lua.diagnostics.disable')[err.type:lower():gsub('_', '-')] then results[#results+1] = buildSyntaxError(uri, err) end end @@ -189,11 +189,11 @@ end ---@async function m.doDiagnostic(uri) - if not config.get 'Lua.diagnostics.enable' then + if not config.get(nil, 'Lua.diagnostics.enable') then return end if files.isLibrary(uri) then - local status = config.get 'Lua.diagnostics.libraryFiles' + local status = config.get(nil, 'Lua.diagnostics.libraryFiles') if status == 'Disable' then return elseif status == 'Opened' then @@ -203,7 +203,7 @@ function m.doDiagnostic(uri) end end if ws.isIgnored(uri) then - local status = config.get 'Lua.diagnostics.ignoredFiles' + local status = config.get(nil, 'Lua.diagnostics.ignoredFiles') if status == 'Disable' then return elseif status == 'Opened' then @@ -333,14 +333,14 @@ local function askForDisable() end function m.diagnosticsAll(force) - if not force and not config.get 'Lua.diagnostics.enable' then + if not force and not config.get(nil, 'Lua.diagnostics.enable') then m.clearAll() return end if not m._start then return end - local delay = config.get 'Lua.diagnostics.workspaceDelay' / 1000 + local delay = config.get(nil, 'Lua.diagnostics.workspaceDelay') / 1000 if not force and delay < 0 then return end @@ -393,7 +393,7 @@ function m.checkWorkspaceDiag() if not await.hasID 'diagnosticsAll' then return end - local speedRate = config.get 'Lua.diagnostics.workspaceRate' + local speedRate = config.get(nil, '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 c0cee9c7..0991b690 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -27,36 +27,37 @@ end ---@async local function updateConfig() - local merged = {} + local baseConfig = {} local cfg = cfgLoader.loadLocalConfig(CONFIGPATH) if cfg then log.debug('load config from local', CONFIGPATH) -- watch directory filewatch.watch(workspace.getAbsolutePath(CONFIGPATH):gsub('[^/\\]+$', '')) - mergeConfig(merged, cfg) + mergeConfig(baseConfig, cfg) + end local rc = cfgLoader.loadRCConfig('.luarc.json') if rc then log.debug('load config from luarc') - mergeConfig(merged, rc) + mergeConfig(baseConfig, rc) end local clientConfig = cfgLoader.loadClientConfig() if clientConfig then log.debug('load config from client') - mergeConfig(merged, clientConfig) + mergeConfig(baseConfig, clientConfig) end - for k, v in pairs(merged) do + for k, v in pairs(baseConfig) do if v == json.null then - merged[k] = nil + baseConfig[k] = nil end end - config.update(merged) - log.debug('loaded config dump:', util.dump(merged)) + config.update(workspace.rootUri,baseConfig) + log.debug('loaded config dump:', util.dump(baseConfig)) end ---@class provider @@ -498,7 +499,7 @@ m.register 'textDocument/completion' { return nil end local triggerCharacter = params.context and params.context.triggerCharacter - if config.get 'editor.acceptSuggestionOnEnter' ~= 'off' then + if config.get(nil, 'editor.acceptSuggestionOnEnter') ~= 'off' then if triggerCharacter == '\n' or triggerCharacter == '{' or triggerCharacter == ',' then @@ -627,7 +628,7 @@ m.register 'textDocument/signatureHelp' { abortByFileUpdate = true, ---@async function (params) - if not config.get 'Lua.signatureHelp.enable' then + if not config.get(nil, 'Lua.signatureHelp.enable') then return nil end workspace.awaitReady() @@ -956,7 +957,7 @@ m.register '$/requestHint' { ---@async function (params) local core = require 'core.hint' - if not config.get 'Lua.hint.enable' then + if not config.get(nil, 'Lua.hint.enable') then return end workspace.awaitReady() @@ -979,7 +980,7 @@ m.register '$/requestHint' { do ---@async local function updateHint(uri) - if not config.get 'Lua.hint.enable' then + if not config.get(nil, 'Lua.hint.enable') then return end local id = 'updateHint' .. uri @@ -1026,7 +1027,7 @@ do end local function refreshStatusBar() - local value = config.get 'Lua.window.statusBar' + local value = config.get(nil, 'Lua.window.statusBar') if value then proto.notify('$/status/show') else diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index 68db9b7f..759a9885 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -47,7 +47,7 @@ local function enable() }, } }) - if config.get 'editor.semanticHighlighting.enabled' == 'configuredByTheme' and not dontShowAgain then + if config.get(nil, 'editor.semanticHighlighting.enabled') == '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 dac72f3f..8f24b7d1 100644 --- a/script/service/telemetry.lua +++ b/script/service/telemetry.lua @@ -74,7 +74,7 @@ end timer.wait(5, function () timer.loop(300, function () - if not config.get 'Lua.telemetry.enable' then + if not config.get(nil, 'Lua.telemetry.enable') then return end local suc, link = pcall(net.connect, 'tcp', 'moe-moe.love', 11577) @@ -93,7 +93,7 @@ timer.wait(5, function () end end)() timer.loop(1, function () - if not config.get 'Lua.telemetry.enable' then + if not config.get(nil, 'Lua.telemetry.enable') then return end net.update() @@ -103,7 +103,7 @@ end) local m = {} function m.updateConfig() - if config.get 'Lua.telemetry.enable' ~= nil then + if config.get(nil, 'Lua.telemetry.enable') ~= nil then return end if m.hasShowedMessage then diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 3a0765bf..544c1f60 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -153,7 +153,7 @@ local function isDeprecated(value) return true elseif doc.type == 'doc.version' then local valids = vm.getValidVersions(doc) - if not valids[config.get 'Lua.runtime.version'] then + if not valids[config.get(nil, 'Lua.runtime.version')] then value._deprecated = true return true end diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index e2149bac..e6bb6c78 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -9,7 +9,7 @@ m.cache = {} --- `aaa/bbb/ccc.lua` 与 `?.lua` 将返回 `aaa.bbb.cccc` local function getOnePath(path, searcher) - local separator = config.get 'Lua.completion.requireSeparator' + local separator = config.get(nil, 'Lua.completion.requireSeparator') local stemPath = path : gsub('%.[^%.]+$', '') : gsub('[/\\%.]+', separator) @@ -28,8 +28,8 @@ local function getOnePath(path, searcher) end function m.getVisiblePath(path) - local searchers = config.get 'Lua.runtime.path' - local strict = config.get 'Lua.runtime.pathStrict' + local searchers = config.get(nil, 'Lua.runtime.path') + local strict = config.get(nil, 'Lua.runtime.pathStrict') path = path:gsub('^[/\\]+', '') local uri = furi.encode(path) local libraryPath = files.getLibraryPath(uri) diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 8b682fde..65b3b1ac 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -30,7 +30,7 @@ m.cache = {} m.watchers = {} m.matchOption = {} ---@type {uri: uri, path: string}[] -m.workSpaces = {} +m.folders = {} function m.initRoot(uri) m.rootUri = uri @@ -47,7 +47,7 @@ end function m.create(uri) log.info('Workspace create: ', uri) local path = m.normalize(furi.decode(uri)) - m.workSpaces[#m.workSpaces+1] = { + m.folders[#m.folders+1] = { uri = uri, path = path, } @@ -92,15 +92,15 @@ function m.getNativeMatcher() end local pattern = {} - -- config.get 'files.exclude' - for path, ignore in pairs(config.get 'files.exclude') do + -- config.get(nil, 'files.exclude' + for path, ignore in pairs(config.get(nil, 'files.exclude')) do if ignore then log.info('Ignore by exclude:', path) pattern[#pattern+1] = path end end - -- config.get 'workspace.useGitIgnore' - if config.get 'Lua.workspace.useGitIgnore' then + -- config.get(nil, 'workspace.useGitIgnore' + if config.get(nil, 'Lua.workspace.useGitIgnore') then local buf = pub.awaitTask('loadFile', furi.encode(m.rootPath .. '/.gitignore')) if buf then for line in buf:gmatch '[^\r\n]+' do @@ -120,8 +120,8 @@ function m.getNativeMatcher() end end end - -- config.get 'workspace.ignoreSubmodules' - if config.get 'Lua.workspace.ignoreSubmodules' then + -- config.get(nil, 'workspace.ignoreSubmodules' + if config.get(nil, 'Lua.workspace.ignoreSubmodules') then local buf = pub.awaitTask('loadFile', furi.encode(m.rootPath .. '/.gitmodules')) if buf then for path in buf:gmatch('path = ([^\r\n]+)') do @@ -130,16 +130,16 @@ function m.getNativeMatcher() end end end - -- config.get 'workspace.library' - for path in pairs(config.get 'Lua.workspace.library') do + -- config.get(nil, 'workspace.library' + for path in pairs(config.get(nil, 'Lua.workspace.library')) do path = m.getAbsolutePath(path) if path then log.info('Ignore by library:', path) pattern[#pattern+1] = path end end - -- config.get 'workspace.ignoreDir' - for _, path in ipairs(config.get 'Lua.workspace.ignoreDir') do + -- config.get(nil, 'workspace.ignoreDir' + for _, path in ipairs(config.get(nil, 'Lua.workspace.ignoreDir')) do log.info('Ignore directory:', path) pattern[#pattern+1] = path end @@ -147,7 +147,7 @@ function m.getNativeMatcher() m.nativeMatcher = glob.gitignore(pattern, m.matchOption, globInteferFace) m.nativeMatcher:setOption('root', m.rootPath) - m.nativeVersion = config.get 'version' + m.nativeVersion = config.get(nil, 'version') return m.nativeMatcher end @@ -158,7 +158,7 @@ function m.getLibraryMatchers() end local librarys = {} - for path in pairs(config.get 'Lua.workspace.library') do + for path in pairs(config.get(nil, 'Lua.workspace.library')) do path = m.getAbsolutePath(path) if path then librarys[m.normalize(path)] = true @@ -181,7 +181,7 @@ function m.getLibraryMatchers() end end - m.libraryVersion = config.get 'version' + m.libraryVersion = config.get(nil, 'version') return m.libraryMatchers end @@ -212,12 +212,12 @@ local function loadFileFactory(root, progressData, isLibrary) return function (path) ---@async local uri = furi.encode(path) if files.isLua(uri) then - if not isLibrary and progressData.preload >= config.get 'Lua.workspace.maxPreload' then + if not isLibrary and progressData.preload >= config.get(nil, '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.get 'Lua.workspace.maxPreload'), + message = lang.script('MWS_MAX_PRELOAD', config.get(nil, 'Lua.workspace.maxPreload')), actions = { { title = lang.script.WINDOW_INCREASE_UPPER_LIMIT, @@ -235,8 +235,8 @@ local function loadFileFactory(root, progressData, isLibrary) { key = 'Lua.workspace.maxPreload', action = 'set', - value = config.get 'Lua.workspace.maxPreload' - + math.max(1000, config.get 'Lua.workspace.maxPreload'), + value = config.get(nil, 'Lua.workspace.maxPreload') + + math.max(1000, config.get(nil, 'Lua.workspace.maxPreload')), } } end @@ -404,7 +404,7 @@ function m.findUrisByFilePath(path) return resultCache[path].results, resultCache[path].posts end tracy.ZoneBeginN('findUrisByFilePath #1') - local strict = config.get 'Lua.runtime.pathStrict' + local strict = config.get(nil, 'Lua.runtime.pathStrict') local results = {} local posts = {} for uri in files.eachFile() do @@ -463,7 +463,7 @@ function m.findUrisByRequirePath(path) local input = path:gsub('%.', '/') :gsub('%%', '%%%%') - for _, luapath in ipairs(config.get 'Lua.runtime.path') do + for _, luapath in ipairs(config.get(nil, 'Lua.runtime.path')) do local part = m.normalize(luapath:gsub('%?', input)) local uris, posts = m.findUrisByFilePath(part) for _, uri in ipairs(uris) do |