diff options
Diffstat (limited to 'script')
25 files changed, 121 insertions, 125 deletions
diff --git a/script/config/config.lua b/script/config/config.lua index ed93078f..4113e670 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -247,7 +247,8 @@ local function getScope(uri, key) ---@type scope local scp = scope.getFolder(uri) or scope.getLinkedScope(uri) if scp then - if not key or scp:get 'config.raw' [key] ~= nil then + if not key + or (scp:get 'config.raw' and scp:get 'config.raw' [key] ~= nil) then return scp end end diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 9a7847f8..cbe782cc 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(nil, 'Lua.completion.displayContext') + local context = config.get(guide.getUri(source), '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(nil, 'Lua.completion.callSnippet') + local snipType = config.get(guide.getUri(source), '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(nil, 'Lua.completion.autoRequire') then + if not config.get(state.uri, '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(nil, 'Lua.diagnostics.globals')[stemName] + and not config.get(state.uri, '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(nil, 'Lua.runtime.version') == 'lua 5.1' - or config.get(nil, 'Lua.runtime.version') == 'luaJIT' then + if config.get(state.uri, 'Lua.runtime.version') == 'lua 5.1' + or config.get(state.uri, '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(nil, 'Lua.completion.showParams') then + if config.get(state.uri, '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(nil, 'Lua.completion.showWord') + local showWord = config.get(state.uri, '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(nil, 'Lua.completion.workspaceWord') and #word >= 2 then + if config.get(state.uri, '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(nil, 'Lua.completion.keywordSnippet') + local snipType = config.get(state.uri, '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 b2b777e7..2ac24933 100644 --- a/script/core/completion/postfix.lua +++ b/script/core/completion/postfix.lua @@ -278,7 +278,7 @@ return function (state, position, results) offset = newOffset - 1 end local symbol = text:sub(offset, offset) - if symbol == config.get(nil, 'Lua.completion.postfix') then + if symbol == config.get(state.uri, 'Lua.completion.postfix') then local wordPosition = guide.offsetToPosition(state, offset - 1) checkPostFix(state, word or '', wordPosition, position, symbol, results) return symbol ~= '.' and symbol ~= ':' diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua index 5fe36c42..1c248646 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(nil, 'Lua.diagnostics.globals')[key] then + if config.get(uri, 'Lua.diagnostics.globals')[key] then return end - if config.get(nil, 'Lua.runtime.special')[key] then + if config.get(uri, '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(nil, 'Lua.runtime.version'))) + message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.get(uri, 'Lua.runtime.version'))) end end cache[id] = { diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 2a21302b..4e2a4976 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(nil, 'Lua.diagnostics.disable')[name] then + if config.get(uri, 'Lua.diagnostics.disable')[name] then return end - local level = config.get(nil, 'Lua.diagnostics.severity')[name] + local level = config.get(uri, 'Lua.diagnostics.severity')[name] or define.DiagnosticDefaultSeverity[name] - local neededFileStatus = config.get(nil, 'Lua.diagnostics.neededFileStatus')[name] + local neededFileStatus = config.get(uri, '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 bd301c7f..d7032c13 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(nil, 'Lua.diagnostics.globals')) do + for name in pairs(config.get(uri, '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 41a50d99..45fc390b 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(nil, 'Lua.diagnostics.globals')[key] then + if config.get(uri, 'Lua.diagnostics.globals')[key] then return end - if config.get(nil, 'Lua.runtime.special')[key] then + if config.get(uri, 'Lua.runtime.special')[key] then return end local node = src.node diff --git a/script/core/hint.lua b/script/core/hint.lua index 82c7371b..eebadb05 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(nil, 'Lua.hint.paramType') then + if not config.get(uri, 'Lua.hint.paramType') then return end else - if not config.get(nil, 'Lua.hint.setType') then + if not config.get(uri, 'Lua.hint.setType') then return end end @@ -99,7 +99,7 @@ end ---@async local function paramName(uri, results, start, finish) - local paramConfig = config.get(nil, 'Lua.hint.paramName') + local paramConfig = config.get(uri, 'Lua.hint.paramName') if not paramConfig or paramConfig == 'Disable' then return end @@ -162,7 +162,7 @@ end ---@async local function awaitHint(uri, results, start, finish) - local awaitConfig = config.get(nil, 'Lua.hint.await') + local awaitConfig = config.get(uri, 'Lua.hint.await') if not awaitConfig then return end diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index c5a42a32..7f34f14d 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -65,11 +65,11 @@ end local function asStringView(source, literal) -- 内部包含转义符? local rawLen = source.finish - source.start - 2 * #source[2] - if config.get(nil, 'Lua.hover.viewString') + if config.get(guide.getUri(source), 'Lua.hover.viewString') and (source[2] == '"' or source[2] == "'") and rawLen > #literal then local view = literal - local max = config.get(nil, 'Lua.hover.viewStringMax') + local max = config.get(guide.getUri(source), '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 436ff913..a39f0eac 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.get(nil, 'Lua.hover.viewNumber') then + if not config.get(guide.getUri(source), '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 3785d479..bd2f81ad 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -3,6 +3,7 @@ local util = require 'utility' local config = require 'config' local infer = require 'core.infer' local await = require 'await' +local guide = require 'parser.guide' local function formatKey(key) if type(key) == 'string' then @@ -136,7 +137,7 @@ end ---@async return function (source) - local maxFields = config.get(nil, 'Lua.hover.previewFields') + local maxFields = config.get(guide.getUri(source), 'Lua.hover.previewFields') if maxFields <= 0 then return 'table' end diff --git a/script/core/infer.lua b/script/core/infer.lua index 9bb1e447..982b8ef3 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -3,6 +3,7 @@ local config = require 'config' local noder = require 'core.noder' local util = require 'utility' local vm = require "vm.vm" +local guide = require "parser.guide" local CLASS = {'CLASS'} local TABLE = {'TABLE'} @@ -232,8 +233,8 @@ local function bindClassOrType(source) return false end -local function cleanInfers(infers) - local version = config.get(nil, 'Lua.runtime.version') +local function cleanInfers(uri, infers) + local version = config.get(uri, 'Lua.runtime.version') local enableInteger = version == 'Lua 5.3' or version == 'Lua 5.4' infers['unknown'] = nil if infers['number'] then @@ -269,7 +270,7 @@ end ---合并对象的推断类型 ---@param infers string[] ---@return string -function m.viewInfers(infers) +function m.viewInfers(uri, infers) if infers[CACHE] then return infers[CACHE] end @@ -298,7 +299,7 @@ function m.viewInfers(infers) return sa < sb end end) - local limit = config.get(nil, 'Lua.hover.enumsLimit') + local limit = config.get(uri, 'Lua.hover.enumsLimit') if limit < 0 then limit = 0 end @@ -510,7 +511,7 @@ function m.searchInfers(source, field, mark) end end end - cleanInfers(infers) + cleanInfers(guide.getUri(source), infers) return infers end @@ -606,7 +607,7 @@ function m.searchAndViewInfers(source, field, mark) return 'any' end local infers = m.searchInfers(source, field, mark) - local view = m.viewInfers(infers) + local view = m.viewInfers(guide.getUri(source), infers) if type(view) == 'boolean' then log.error('Why view is boolean?', util.dump(infers)) return 'any' @@ -630,8 +631,8 @@ function m.getClass(source) end end end - cleanInfers(infers) - local view = m.viewInfers(infers) + cleanInfers(guide.getUri(source), infers) + local view = m.viewInfers(guide.getUri(source), infers) if view == 'any' then return nil end diff --git a/script/core/noder.lua b/script/core/noder.lua index 373644de..6681fa7c 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -497,7 +497,7 @@ local function getNodeKey(source) if methodNode then return getNodeKey(methodNode) end - if config.get(nil, 'Lua.IntelliSense.traceFieldInject') then + if config.get(guide.getUri(source), 'Lua.IntelliSense.traceFieldInject') then local localValueID = getLocalValueID(source) if localValueID then return localValueID @@ -822,7 +822,7 @@ local function bindValue(noders, source, id) local bindDocs = source.bindDocs if source.type == 'getlocal' or source.type == 'setlocal' then - if not config.get(nil, 'Lua.IntelliSense.traceLocalSet') then + if not config.get(guide.getUri(source), 'Lua.IntelliSense.traceLocalSet') then return end bindDocs = source.node.bindDocs @@ -837,7 +837,7 @@ local function bindValue(noders, source, id) end -- x = y : x -> y pushForward(noders, id, valueID, INFO_REJECT_SET) - if not config.get(nil, 'Lua.IntelliSense.traceBeSetted') + if not config.get(guide.getUri(source), 'Lua.IntelliSense.traceBeSetted') and source.type ~= 'local' then return end @@ -1329,7 +1329,7 @@ compileNodeMap = util.switch() , index ) pushForward(noders, returnID, getID(rtnObj)) - if config.get(nil, 'Lua.IntelliSense.traceReturn') then + if config.get(guide.getUri(source), '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 291819f2..12848d2b 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -9,10 +9,8 @@ local converter = require 'proto.converter' local infer = require 'core.infer' local config = require 'config' -local isEnhanced = config.get(nil, 'Lua.color.mode') == 'SemanticEnhanced' - local Care = {} -Care['getglobal'] = function (source, results) +Care['getglobal'] = function (source, options, results) local isLib = vm.isGlobalLibraryName(source[1]) local isFunc = false local value = source.value @@ -21,7 +19,7 @@ Care['getglobal'] = function (source, results) isFunc = true elseif source.parent.type == 'call' then isFunc = true - elseif isEnhanced then + elseif options.isEnhanced then isFunc = infer.hasType(source, 'function') end @@ -36,7 +34,7 @@ Care['getglobal'] = function (source, results) } end Care['setglobal'] = Care['getglobal'] -Care['getmethod'] = function (source, results) +Care['getmethod'] = function (source, options, results) local method = source.method if method and method.type == 'method' then results[#results+1] = { @@ -48,7 +46,7 @@ Care['getmethod'] = function (source, results) end end Care['setmethod'] = Care['getmethod'] -Care['field'] = function (source, results) +Care['field'] = function (source, options, results) local modifiers = 0 if source.parent and source.parent.type == 'tablefield' then modifiers = define.TokenModifiers.declaration @@ -65,7 +63,7 @@ Care['field'] = function (source, results) return end end - if isEnhanced and infer.hasType(source, 'function') then + if options.isEnhanced and infer.hasType(source, 'function') then results[#results+1] = { start = source.start, finish = source.finish, @@ -90,7 +88,7 @@ Care['field'] = function (source, results) modifieres = modifiers, } end -Care['getlocal'] = function (source, results) +Care['getlocal'] = function (source, options, results) local loc = source.node -- 1. 值为函数的局部变量 | Local variable whose value is a function if loc.refs then @@ -127,7 +125,7 @@ Care['getlocal'] = function (source, results) return end -- 5. References to other functions - if isEnhanced and infer.hasType(loc, 'function') then + if options.isEnhanced and infer.hasType(loc, 'function') then results[#results+1] = { start = source.start, finish = source.finish, @@ -137,7 +135,7 @@ Care['getlocal'] = function (source, results) return end -- 6. Class declaration - if isEnhanced then + if options.isEnhanced then -- search all defs for _, def in ipairs(vm.getDefs(source)) do if def.bindDocs then @@ -214,7 +212,7 @@ Care['getlocal'] = function (source, results) } end Care['setlocal'] = Care['getlocal'] -Care['local'] = function (source, results) -- Local declaration, i.e. "local x", "local y = z", or "local function() end" +Care['local'] = function (source, options, results) -- Local declaration, i.e. "local x", "local y = z", or "local function() end" if source[1] == '_ENV' or source[1] == 'self' then return @@ -231,7 +229,7 @@ Care['local'] = function (source, results) -- Local declaration, i.e. "local x", if source.value then local isFunction = false - if isEnhanced then + if options.isEnhanced then isFunction = source.value.type == 'function' or infer.hasType(source.value, 'function') else isFunction = source.value.type == 'function' @@ -299,21 +297,21 @@ Care['local'] = function (source, results) -- Local declaration, i.e. "local x", modifieres = modifiers, } end -Care['doc.return.name'] = function (source, results) +Care['doc.return.name'] = function (source, options, results) results[#results+1] = { start = source.start, finish = source.finish, type = define.TokenTypes.parameter, } end -Care['doc.tailcomment'] = function (source, results) +Care['doc.tailcomment'] = function (source, options, results) results[#results+1] = { start = source.start, finish = source.finish, type = define.TokenTypes.comment, } end -Care['doc.type.name'] = function (source, results) +Care['doc.type.name'] = function (source, options, results) if source.typeGeneric then results[#results+1] = { start = source.start, @@ -323,14 +321,14 @@ Care['doc.type.name'] = function (source, results) end end -Care['nonstandardSymbol.comment'] = function (source, results) +Care['nonstandardSymbol.comment'] = function (source, options, results) results[#results+1] = { start = source.start, finish = source.finish, type = define.TokenTypes.comment, } end -Care['nonstandardSymbol.continue'] = function (source, results) +Care['nonstandardSymbol.continue'] = function (source, options, results) results[#results+1] = { start = source.start, finish = source.finish, @@ -367,27 +365,24 @@ local function buildTokens(uri, results) return tokens end -config.watch(function (key, value) - if key == 'Lua.color.mode' then - isEnhanced = value == 'SemanticEnhanced' - end -end) - ---@async return function (uri, start, finish) local state = files.getState(uri) - local text = files.getText(uri) if not state then return nil end + local options = { + isEnhanced = config.get(uri, 'Lua.color.mode') == 'SemanticEnhanced', + } + local results = {} guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async local method = Care[source.type] if not method then return end - method(source, results) + method(source, options, results) await.delay() end) diff --git a/script/files.lua b/script/files.lua index ecee9098..e9aae50b 100644 --- a/script/files.lua +++ b/script/files.lua @@ -180,7 +180,7 @@ function m.setText(uri, text, isTrust, version) return end if not isTrust then - local encoding = config.get(nil, 'Lua.runtime.fileEncoding') + local encoding = config.get(uri, 'Lua.runtime.fileEncoding') text = encoder.decode(encoding, text) end file.version = version @@ -442,7 +442,7 @@ function m.compileState(uri, text) local client = require 'client' if not m.isOpen(uri) and not m.isLibrary(uri) - and #text >= config.get(nil, 'Lua.workspace.preloadFileSize') * 1000 then + and #text >= config.get(uri, 'Lua.workspace.preloadFileSize') * 1000 then if not m.notifyCache['preloadFileSize'] then m.notifyCache['preloadFileSize'] = {} m.notifyCache['skipLargeFileCount'] = 0 @@ -452,7 +452,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(nil, 'Lua.workspace.preloadFileSize') + , config.get(uri, 'Lua.workspace.preloadFileSize') , #text / 1000 ) if m.notifyCache['skipLargeFileCount'] <= 1 then @@ -468,11 +468,11 @@ function m.compileState(uri, text) local clock = os.clock() local state, err = parser.compile(text , 'Lua' - , config.get(nil, 'Lua.runtime.version') + , config.get(uri, 'Lua.runtime.version') , { - special = config.get(nil, 'Lua.runtime.special'), - unicodeName = config.get(nil, 'Lua.runtime.unicodeName'), - nonstandardSymbol = config.get(nil, 'Lua.runtime.nonstandardSymbol'), + special = config.get(uri, 'Lua.runtime.special'), + unicodeName = config.get(uri, 'Lua.runtime.unicodeName'), + nonstandardSymbol = config.get(uri, 'Lua.runtime.nonstandardSymbol'), } ) local passed = os.clock() - clock @@ -623,9 +623,9 @@ function m.getCache(uri) end --- 获取文件关联 -function m.getAssoc() +function m.getAssoc(uri) local patt = {} - for k, v in pairs(config.get(nil, 'files.associations')) do + for k, v in pairs(config.get(uri, 'files.associations')) do if v == 'lua' then patt[#patt+1] = k end @@ -645,7 +645,7 @@ function m.isLua(uri) if ext == 'lua' then return true end - local matcher = m.getAssoc() + local matcher = m.getAssoc(uri) local path = furi.decode(uri) return matcher(path) end diff --git a/script/library.lua b/script/library.lua index cddb19fd..d0f19c30 100644 --- a/script/library.lua +++ b/script/library.lua @@ -14,8 +14,8 @@ local encoder = require 'encoder' local m = {} -local function getDocFormater() - local version = config.get(nil, 'Lua.runtime.version') +local function getDocFormater(uri) + local version = config.get(uri, 'Lua.runtime.version') if client.isVSCode() then if version == 'Lua 5.1' then return 'HOVER_NATIVE_DOCUMENT_LUA51' @@ -43,8 +43,8 @@ local function getDocFormater() end end -local function convertLink(text) - local fmt = getDocFormater() +local function convertLink(uri, text) + local fmt = getDocFormater(uri) return text:gsub('%$([%.%w]+)', function (name) local lastDot = '' if name:sub(-1) == '.' then @@ -82,7 +82,7 @@ local function createViewDocument(name) return ('[%s](%s)'):format(lang.script.HOVER_VIEW_DOCUMENTS, lang.script(fmt, 'pdf-' .. name)) end -local function compileSingleMetaDoc(script, metaLang, status) +local function compileSingleMetaDoc(uri, script, metaLang, status) if not script then return nil end @@ -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(nil, 'Lua.runtime.version') == 'LuaJIT' then + if config.get(uri, 'Lua.runtime.version') == 'LuaJIT' then version = 5.1 jit = true else - version = tonumber(config.get(nil, 'Lua.runtime.version'):sub(-3)) + version = tonumber(config.get(uri, 'Lua.runtime.version'):sub(-3)) jit = false end @@ -122,7 +122,7 @@ local function compileSingleMetaDoc(script, metaLang, status) compileBuf[#compileBuf+1] = '---\n' for line in util.eachLine(des) do compileBuf[#compileBuf+1] = '---' - compileBuf[#compileBuf+1] = convertLink(line) + compileBuf[#compileBuf+1] = convertLink(uri, line) compileBuf[#compileBuf+1] = '\n' end local viewDocument = createViewDocument(name) @@ -138,7 +138,7 @@ local function compileSingleMetaDoc(script, metaLang, status) if not des then des = ('Miss locale <%s>'):format(name) end - compileBuf[#compileBuf+1] = convertLink(des) + compileBuf[#compileBuf+1] = convertLink(uri, des) compileBuf[#compileBuf+1] = '\n' end, ALIVE = function (str) @@ -202,9 +202,9 @@ local function initBuiltIn() return end local langID = lang.id - 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('%$%{(.-)%}', { + local version = config.get(uri, 'Lua.runtime.version') + local encoding = config.get(uri, 'Lua.runtime.fileEncoding') + local metaPath = fs.path(METAPATH) / config.get(uri, 'Lua.runtime.meta'):gsub('%$%{(.-)%}', { version = version, language = langID, encoding = encoding, @@ -232,13 +232,13 @@ local function initBuiltIn() local out = fsu.dummyFS() local templateDir = ROOT / 'meta' / 'template' for libName, status in pairs(define.BuiltIn) do - status = config.get(nil, 'Lua.runtime.builtin')[libName] or status + status = config.get(uri, 'Lua.runtime.builtin')[libName] or status if status == 'disable' then goto CONTINUE end libName = libName .. '.lua' local libPath = templateDir / libName - local metaDoc = compileSingleMetaDoc(fsu.loadFile(libPath), metaLang, status) + local metaDoc = compileSingleMetaDoc(uri, fsu.loadFile(libPath), metaLang, status) if metaDoc then local outPath = metaPath / libName metaDoc = encoder.encode(encoding, metaDoc, 'auto') @@ -313,7 +313,7 @@ end local function load3rdConfig() local configs = {} load3rdConfigInDir(innerThirdDir, configs, true) - local thirdDirs = config.get(nil, 'Lua.workspace.userThirdParty') + local thirdDirs = config.get(uri, 'Lua.workspace.userThirdParty') for _, thirdDir in ipairs(thirdDirs) do load3rdConfigInDir(fs.path(thirdDir), configs) end @@ -455,7 +455,7 @@ local function check3rd(uri) if hasAsked then return end - if not config.get(nil, 'Lua.workspace.checkThirdParty') then + if not config.get(uri, 'Lua.workspace.checkThirdParty') then return end if thirdConfigs == nil then @@ -477,7 +477,7 @@ end config.watch(function (key, value, oldValue) if key:find '^Lua.runtime' then - initBuiltIn() + initBuiltIn(uri) end end) diff --git a/script/progress.lua b/script/progress.lua index d1595cf8..d5c174ce 100644 --- a/script/progress.lua +++ b/script/progress.lua @@ -10,6 +10,7 @@ local m = {} m.map = {} ---@class progress +---@field _scp scope local mt = {} mt.__index = mt mt._token = nil @@ -83,7 +84,7 @@ function mt:_update() and self._clock + self._delay <= os.clock() then self._updated = os.clock() self._dirty = false - if not config.get(nil, 'Lua.window.progressBar') then + if not config.get(self._scp.uri, 'Lua.window.progressBar') then return end proto.request('window/workDoneProgress/create', { @@ -106,7 +107,7 @@ function mt:_update() if not self._showed then return end - if not config.get(nil, 'Lua.window.progressBar') then + if not config.get(self._scp.uri, 'Lua.window.progressBar') then self:remove() return end @@ -143,14 +144,16 @@ function m.update() end ---创建一个进度条 +---@param scp scope ---@param title string # 标题 ---@param delay number # 至少经过这么久之后才会显示出来 -function m.create(title, delay) +function m.create(scp, title, delay) local prog = setmetatable({ _token = nextToken(), _title = title, _clock = os.clock(), _delay = delay, + _scp = scp, }, mt) m.map[prog._token] = prog diff --git a/script/provider/completion.lua b/script/provider/completion.lua index 8e529e95..6c215f15 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(nil, 'Lua.completion.postfix') + local postfix = config.get(uri, '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(nil, 'Lua.completion.enable') then + if config.get(uri, 'Lua.completion.enable') then disable() enable() end diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index fb9a745e..1be7d626 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(nil, 'Lua.runtime.version') + local version = err.info and err.info.version or config.get(uri, '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(nil, 'Lua.diagnostics.disable')[err.type:lower():gsub('_', '-')] then + if not config.get(uri, '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(nil, 'Lua.diagnostics.enable') then + if not config.get(uri, 'Lua.diagnostics.enable') then return end if files.isLibrary(uri) then - local status = config.get(nil, 'Lua.diagnostics.libraryFiles') + local status = config.get(uri, '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(nil, 'Lua.diagnostics.ignoredFiles') + local status = config.get(uri, 'Lua.diagnostics.ignoredFiles') if status == 'Disable' then return elseif status == 'Opened' then @@ -332,14 +332,14 @@ local function askForDisable() end function m.diagnosticsAll(force) - if not force and not config.get(nil, 'Lua.diagnostics.enable') then + if not force and not config.get(uri, 'Lua.diagnostics.enable') then m.clearAll() return end if not m._start then return end - local delay = config.get(nil, 'Lua.diagnostics.workspaceDelay') / 1000 + local delay = config.get(uri, 'Lua.diagnostics.workspaceDelay') / 1000 if not force and delay < 0 then return end @@ -392,7 +392,7 @@ function m.checkWorkspaceDiag() if not await.hasID 'diagnosticsAll' then return end - local speedRate = config.get(nil, 'Lua.diagnostics.workspaceRate') + local speedRate = config.get(uri, '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 6b7a56b5..9d853e06 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -252,11 +252,11 @@ m.register 'textDocument/hover' { abortByFileUpdate = true, ---@async function (params) - if not config.get(nil, 'Lua.hover.enable') then - return - end local doc = params.textDocument local uri = files.getRealUri(doc.uri) + if not config.get(uri, 'Lua.hover.enable') then + return + end if not workspace.isReady() then local count, max = workspace.getLoadingProcess(uri) return { @@ -493,7 +493,7 @@ m.register 'textDocument/completion' { return nil end local triggerCharacter = params.context and params.context.triggerCharacter - if config.get(nil, 'editor.acceptSuggestionOnEnter') ~= 'off' then + if config.get(uri, 'editor.acceptSuggestionOnEnter') ~= 'off' then if triggerCharacter == '\n' or triggerCharacter == '{' or triggerCharacter == ',' then @@ -1020,7 +1020,7 @@ do end local function refreshStatusBar() - local value = config.get(nil, 'Lua.window.statusBar') + local value = config.get(uri, '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 759a9885..2a8013db 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -47,7 +47,7 @@ local function enable() }, } }) - if config.get(nil, 'editor.semanticHighlighting.enabled') == 'configuredByTheme' and not dontShowAgain then + if config.get(uri, '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 8f24b7d1..b61e565b 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(nil, 'Lua.telemetry.enable') then + if not config.get(uri, '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(nil, 'Lua.telemetry.enable') then + if not config.get(uri, 'Lua.telemetry.enable') then return end net.update() @@ -103,7 +103,7 @@ end) local m = {} function m.updateConfig() - if config.get(nil, 'Lua.telemetry.enable') ~= nil then + if config.get(uri, 'Lua.telemetry.enable') ~= nil then return end if m.hasShowedMessage then diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index f179c684..c635b2a9 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(nil, 'Lua.runtime.version')] then + if not valids[config.get(guide.getUri(value), '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 a6af2612..a0313a58 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(nil, 'Lua.completion.requireSeparator') + local separator = config.get(uri, '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(nil, 'Lua.runtime.path') - local strict = config.get(nil, 'Lua.runtime.pathStrict') + local searchers = config.get(uri, 'Lua.runtime.path') + local strict = config.get(uri, 'Lua.runtime.pathStrict') path = workspace.normalize(path) local uri = furi.encode(path) local libraryPath = files.getLibraryPath(uri) @@ -86,7 +86,7 @@ function m.findUrisByRequirePath(path) if type(path) ~= 'string' then return {} end - local separator = config.get(nil, 'Lua.completion.requireSeparator') + local separator = config.get(uri, 'Lua.completion.requireSeparator') local fspath = path:gsub('%' .. separator, '/') local vm = require 'vm' local cache = vm.getCache 'findUrisByRequirePath' diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 2376f1e8..e8a67ccc 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -80,14 +80,12 @@ function m.getNativeMatcher(scp) end local pattern = {} - -- config.get(nil, 'files.exclude' for path, ignore in pairs(config.get(scp.uri, 'files.exclude')) do if ignore then log.info('Ignore by exclude:', path) pattern[#pattern+1] = path end end - -- config.get(nil, 'workspace.useGitIgnore' if config.get(scp.uri, 'Lua.workspace.useGitIgnore') then local buf = pub.awaitTask('loadFile', m.rootUri .. '/.gitignore') if buf then @@ -108,7 +106,6 @@ function m.getNativeMatcher(scp) end end end - -- config.get(nil, 'workspace.ignoreSubmodules' if config.get(scp.uri, 'Lua.workspace.ignoreSubmodules') then local buf = pub.awaitTask('loadFile', m.rootUri .. '/.gitmodules') if buf then @@ -118,7 +115,6 @@ function m.getNativeMatcher(scp) end end end - -- config.get(nil, 'workspace.library' for path in pairs(config.get(scp.uri, 'Lua.workspace.library')) do path = m.getAbsolutePath(path) if path then @@ -126,7 +122,6 @@ function m.getNativeMatcher(scp) pattern[#pattern+1] = path end end - -- config.get(nil, 'workspace.ignoreDir' for _, path in ipairs(config.get(scp.uri, 'Lua.workspace.ignoreDir')) do log.info('Ignore directory:', path) pattern[#pattern+1] = path |