summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-rw-r--r--script/core/code-action.lua14
-rw-r--r--script/core/collector.lua52
-rw-r--r--script/core/command/autoRequire.lua7
-rw-r--r--script/core/completion/completion.lua147
-rw-r--r--script/core/completion/postfix.lua2
-rw-r--r--script/core/definition.lua2
-rw-r--r--script/core/diagnostics/circle-doc-class.lua2
-rw-r--r--script/core/diagnostics/deprecated.lua6
-rw-r--r--script/core/diagnostics/different-requires.lua2
-rw-r--r--script/core/diagnostics/duplicate-doc-class.lua2
-rw-r--r--script/core/diagnostics/init.lua6
-rw-r--r--script/core/diagnostics/lowercase-global.lua2
-rw-r--r--script/core/diagnostics/type-check.lua16
-rw-r--r--script/core/diagnostics/undefined-doc-class.lua2
-rw-r--r--script/core/diagnostics/undefined-global.lua4
-rw-r--r--script/core/hint.lua8
-rw-r--r--script/core/hover/description.lua14
-rw-r--r--script/core/hover/label.lua2
-rw-r--r--script/core/hover/return.lua3
-rw-r--r--script/core/hover/table.lua3
-rw-r--r--script/core/infer.lua17
-rw-r--r--script/core/noder.lua8
-rw-r--r--script/core/searcher.lua15
-rw-r--r--script/core/semantic-tokens.lua45
-rw-r--r--script/core/type-definition.lua2
25 files changed, 158 insertions, 225 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index ad048c48..b2a6fac9 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -49,7 +49,7 @@ local function disableDiagnostic(uri, code, start, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_DISABLE_DIAG,
- command = 'lua.setConfig:' .. sp:get_id(),
+ command = 'lua.setConfig',
arguments = {
{
key = 'Lua.diagnostics.disable',
@@ -86,7 +86,7 @@ local function markGlobal(uri, name, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_MARK_GLOBAL,
- command = 'lua.setConfig:' .. sp:get_id(),
+ command = 'lua.setConfig',
arguments = {
{
key = 'Lua.diagnostics.globals',
@@ -105,7 +105,7 @@ local function changeVersion(uri, version, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_RUNTIME_VERSION,
- command = 'lua.setConfig:' .. sp:get_id(),
+ command = 'lua.setConfig',
arguments = {
{
key = 'Lua.runtime.version',
@@ -223,7 +223,7 @@ local function solveSyntaxUnicodeName(uri, err, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_UNICODE_NAME,
- command = 'lua.setConfig:' .. sp:get_id(),
+ command = 'lua.setConfig',
arguments = {
{
key = 'Lua.runtime.unicodeName',
@@ -280,7 +280,7 @@ local function solveAmbiguity1(uri, diag, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_ADD_BRACKETS,
- command = 'lua.solve:' .. sp:get_id(),
+ command = 'lua.solve',
arguments = {
{
name = 'ambiguity-1',
@@ -298,7 +298,7 @@ local function solveTrailingSpace(uri, diag, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_REMOVE_SPACE,
- command = 'lua.removeSpace:' .. sp:get_id(),
+ command = 'lua.removeSpace',
arguments = {
{
uri = uri,
@@ -570,7 +570,7 @@ local function checkJsonToLua(results, uri, start, finish)
kind = 'refactor.rewrite',
command = {
title = lang.script.COMMAND_JSON_TO_LUA,
- command = 'lua.jsonToLua:' .. sp:get_id(),
+ command = 'lua.jsonToLua',
arguments = {
{
uri = uri,
diff --git a/script/core/collector.lua b/script/core/collector.lua
index 3293c9fe..2f29fc37 100644
--- a/script/core/collector.lua
+++ b/script/core/collector.lua
@@ -1,3 +1,6 @@
+local scope = require 'workspace.scope'
+local ws = require 'workspace'
+
local collect = {}
local subscribed = {}
@@ -58,17 +61,56 @@ end
local DUMMY_FUNCTION = function () end
--- 迭代某个名字的订阅
+---@param uri uri
---@param name string
-function m.each(name)
+function m.each(uri, name)
local nameCollect = collect[name]
if not nameCollect then
return DUMMY_FUNCTION
end
- local uri, value
- return function ()
- uri, value = next(nameCollect, uri)
- return value, uri
+ ---@type scope
+ local scp = scope.getFolder(uri)
+ or scope.getLinkedScope(uri)
+ or scope.fallback
+
+ local curi, value
+ local function getNext()
+ curi, value = next(nameCollect, curi)
+ if not curi then
+ return nil, nil
+ end
+ if not scp:isChildUri(curi)
+ and not scp:isLinkedUri(curi) then
+ return getNext()
+ end
+
+ return value, curi
end
+ return getNext
end
+--- 迭代某个名字的引用订阅
+---@param uri uri
+---@param name string
+function m.eachRef(uri, name)
+ local nameCollect = collect[name]
+ if not nameCollect then
+ return DUMMY_FUNCTION
+ end
+ ---@type scope
+ if scope.getFolder(uri) then
+ return m.each(uri, name)
+ end
+
+ local curi, value
+ local function getNext()
+ curi, value = next(nameCollect, curi)
+ if not curi then
+ return nil, nil
+ end
+
+ return value, curi
+ end
+ return getNext
+end
return m
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua
index 30bd13a1..c0deecfc 100644
--- a/script/core/command/autoRequire.lua
+++ b/script/core/command/autoRequire.lua
@@ -64,7 +64,7 @@ local function findInsertRow(uri)
end
---@async
-local function askAutoRequire(visiblePaths)
+local function askAutoRequire(uri, visiblePaths)
local selects = {}
local nameMap = {}
for _, visible in ipairs(visiblePaths) do
@@ -91,6 +91,7 @@ local function askAutoRequire(visiblePaths)
key = 'Lua.completion.autoRequire',
action = 'set',
value = false,
+ uri = uri,
}
}
return
@@ -137,7 +138,7 @@ return function (data)
end
local path = furi.decode(target)
- local visiblePaths = rpath.getVisiblePath(path)
+ local visiblePaths = rpath.getVisiblePath(uri, path)
if not visiblePaths or #visiblePaths == 0 then
return
end
@@ -145,7 +146,7 @@ return function (data)
return #a.expect < #b.expect
end)
- local result = askAutoRequire(visiblePaths)
+ local result = askAutoRequire(uri, visiblePaths)
if not result then
return
end
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 425c8026..28e9d108 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(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 '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 '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 '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)
@@ -367,7 +367,7 @@ local function checkModule(state, word, position, results)
commitCharacters = {'.'},
command = {
title = 'autoRequire',
- command = 'lua.autoRequire:' .. sp:get_id(),
+ command = 'lua.autoRequire',
arguments = {
{
uri = guide.getUri(state.ast),
@@ -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(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 '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
@@ -584,14 +584,14 @@ end
---@async
local function checkGlobal(state, word, startPos, position, parent, oop, results)
local locals = guide.getVisibleLocals(state.ast, position)
- local globals = vm.getGlobalSets '*'
+ local globals = vm.getGlobalSets(state.uri, '*')
checkFieldOfRefs(globals, state, word, startPos, position, parent, oop, results, locals, 'global')
end
---@async
local function checkField(state, word, start, position, parent, oop, results)
if parent.tag == '_ENV' or parent.special == '_G' then
- local globals = vm.getGlobalSets '*'
+ local globals = vm.getGlobalSets(state.uri, '*')
checkFieldOfRefs(globals, state, word, start, position, parent, oop, results)
else
local refs = vm.getRefs(parent, '*')
@@ -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(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 '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 '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 = {
@@ -887,7 +887,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
goto CONTINUE
end
local path = workspace.getRelativePath(uri)
- local infos = rpath.getVisiblePath(path)
+ local infos = rpath.getVisiblePath(uri, path)
for _, info in ipairs(infos) do
if matchKey(literal, info.expect) then
if not collect[info.expect] then
@@ -1628,7 +1628,7 @@ local function tryluaDocBySource(state, position, source, results)
if source.type == 'doc.extends.name' then
if source.parent.type == 'doc.class' then
local used = {}
- for _, doc in ipairs(vm.getDocDefines '*') do
+ for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
if doc.type == 'doc.class.name'
and doc.parent ~= source.parent
and not used[doc[1]]
@@ -1649,7 +1649,7 @@ local function tryluaDocBySource(state, position, source, results)
return true
elseif source.type == 'doc.type.name' then
local used = {}
- for _, doc in ipairs(vm.getDocDefines '*') do
+ for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
if (doc.type == 'doc.class.name' or doc.type == 'doc.alias.name')
and doc.parent ~= source.parent
and not used[doc[1]]
@@ -1727,7 +1727,7 @@ end
local function tryluaDocByErr(state, position, err, docState, results)
if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then
- for _, doc in ipairs(vm.getDocDefines '*') do
+ for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
if doc.type == 'doc.class.name'
and doc.parent ~= docState then
results[#results+1] = {
@@ -1737,7 +1737,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
end
end
elseif err.type == 'LUADOC_MISS_TYPE_NAME' then
- for _, doc in ipairs(vm.getDocDefines '*') do
+ for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
if (doc.type == 'doc.class.name' or doc.type == 'doc.alias.name') then
results[#results+1] = {
label = doc[1],
@@ -1940,89 +1940,6 @@ local function tryComment(state, position, results)
checkCommon(state, word, position, results)
end
-local function makeCache(uri, position, results)
- local cache = workspace.getCache 'completion'
- if not uri then
- cache.results = nil
- return
- end
- local text = files.getText(uri)
- local state = files.getState(uri)
- local word = lookBackward.findWord(text, guide.positionToOffset(state, position))
- if not word or #word < 2 then
- cache.results = nil
- return
- end
- cache.results = results
- cache.position= position
- cache.word = word:lower()
- cache.length = #word
- cache.uri = uri
-end
-
-local function isValidCache(word, result)
- if result.kind == define.CompletionItemKind.Text then
- return false
- end
- local match = result.match or result.label
- if matchKey(word, match) then
- return true
- end
- if result.textEdit then
- match = result.textEdit.newText:match '[%w_]+'
- if match and matchKey(word, match) then
- return true
- end
- end
- return false
-end
-
-local function getCache(uri, position)
- do return nil end
- local cache = workspace.getCache 'completion'
- if not cache.results then
- return nil
- end
- if cache.uri ~= uri then
- return nil
- end
- local text = files.getText(uri)
- local state = files.getState(uri)
- local word = lookBackward.findWord(text, guide.positionToOffset(state, position))
- if not word then
- return nil
- end
- if word:sub(1, #cache.word):lower() ~= cache.word then
- return nil
- end
-
- local ext = #word - cache.length
- cache.length = #word
- local results = cache.results
- for i = #results, 1, -1 do
- local result = results[i]
- if isValidCache(word, result) then
- if result.textEdit then
- result.textEdit.finish = result.textEdit.finish + ext
- end
- else
- results[i] = results[#results]
- results[#results] = nil
- end
- end
-
- if results.enableCommon then
- checkCommon(state, word, position, results)
- end
-
- return cache.results
-end
-
-local function clearCache()
- local cache = workspace.getCache 'completion'
- cache.results = nil
-end
-
---@async
local function tryCompletions(state, position, triggerCharacter, results)
local text = state.lua
@@ -2052,56 +1969,30 @@ end
---@async
local function completion(uri, position, triggerCharacter)
- tracy.ZoneBeginN 'completion cache'
- local results = getCache(uri, position)
- tracy.ZoneEnd()
- if results then
- return results
- end
- await.delay()
- tracy.ZoneBeginN 'completion #1'
local state = files.getState(uri)
if not state then
return nil
end
- results = {}
clearStack()
- tracy.ZoneEnd()
+ local results = {}
tracy.ZoneBeginN 'completion #2'
tryCompletions(state, position, triggerCharacter, results)
tracy.ZoneEnd()
if #results == 0 then
- clearCache()
return nil
end
- --tracy.ZoneBeginN 'completion #3'
- --makeCache(uri, position, results)
- --tracy.ZoneEnd()
return results
end
---@async
local function resolve(id)
local item = resolveStack(id)
- local cache = workspace.getCache 'completion'
- if item and cache.results then
- for _, res in ipairs(cache.results) do
- if res and res.id == id then
- for k, v in pairs(item) do
- res[k] = v
- end
- res.id = nil
- break
- end
- end
- end
return item
end
return {
completion = completion,
resolve = resolve,
- clearCache = clearCache,
}
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua
index 0395e2a5..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 '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/definition.lua b/script/core/definition.lua
index eadae30f..6c6b3df3 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -75,7 +75,7 @@ local function checkRequire(source, offset)
return nil
end
if libName == 'require' then
- return rpath.findUrisByRequirePath(literal)
+ return rpath.findUrisByRequirePath(guide.getUri(source), literal)
elseif libName == 'dofile'
or libName == 'loadfile' then
return workspace.findUrisByFilePath(literal)
diff --git a/script/core/diagnostics/circle-doc-class.lua b/script/core/diagnostics/circle-doc-class.lua
index ae6d4d3b..61dc46b4 100644
--- a/script/core/diagnostics/circle-doc-class.lua
+++ b/script/core/diagnostics/circle-doc-class.lua
@@ -40,7 +40,7 @@ return function (uri, callback)
end
if not mark[newName] then
mark[newName] = true
- local docs = vm.getDocDefines(newName)
+ local docs = vm.getDocDefines(uri, newName)
for _, otherDoc in ipairs(docs) do
if otherDoc.type == 'doc.class.name' then
list[#list+1] = otherDoc.parent
diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua
index e9a1fef7..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 'Lua.diagnostics.globals'[key] then
+ if config.get(uri, 'Lua.diagnostics.globals')[key] then
return
end
- if config.get '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 '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/different-requires.lua b/script/core/diagnostics/different-requires.lua
index 3a49ceef..de063c9f 100644
--- a/script/core/diagnostics/different-requires.lua
+++ b/script/core/diagnostics/different-requires.lua
@@ -21,7 +21,7 @@ return function (uri, callback)
return
end
local literal = arg1[1]
- local results = rpath.findUrisByRequirePath(literal)
+ local results = rpath.findUrisByRequirePath(uri, literal)
if not results or #results ~= 1 then
return
end
diff --git a/script/core/diagnostics/duplicate-doc-class.lua b/script/core/diagnostics/duplicate-doc-class.lua
index 97e2089a..5114a54f 100644
--- a/script/core/diagnostics/duplicate-doc-class.lua
+++ b/script/core/diagnostics/duplicate-doc-class.lua
@@ -19,7 +19,7 @@ return function (uri, callback)
if doc.type == 'doc.alias' then
local name = guide.getKeyName(doc)
if not cache[name] then
- local docs = vm.getDocDefines(name)
+ local docs = vm.getDocDefines(uri, name)
cache[name] = {}
for _, otherDoc in ipairs(docs) do
if otherDoc.type == 'doc.class.name'
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 4950900b..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 'Lua.diagnostics.disable'[name] then
+ if config.get(uri, 'Lua.diagnostics.disable')[name] then
return
end
- local level = config.get 'Lua.diagnostics.severity'[name]
+ local level = config.get(uri, 'Lua.diagnostics.severity')[name]
or define.DiagnosticDefaultSeverity[name]
- local neededFileStatus = config.get '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 299ac110..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 '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/type-check.lua b/script/core/diagnostics/type-check.lua
index 8728b169..5f37312e 100644
--- a/script/core/diagnostics/type-check.lua
+++ b/script/core/diagnostics/type-check.lua
@@ -36,11 +36,11 @@ local function isTable(name)
return false
end
-local function isUserDefineClass(name)
+local function isUserDefineClass(uri, name)
if vm.isBuiltinType(name) then
return false
else
- local defs = vm.getDocDefines(name)
+ local defs = vm.getDocDefines(uri, name)
for _, v in ipairs(defs) do
if v.type == 'doc.class.name' then
return true
@@ -116,10 +116,10 @@ end
-- end
-- end
-local function addFatherClass(infers)
+local function addFatherClass(uri, infers)
for k in pairs(infers) do
if type(k) == 'string' then
- local docDefs = vm.getDocDefines(k)
+ local docDefs = vm.getDocDefines(uri, k)
for _, doc in ipairs(docDefs) do
if doc.parent
and doc.parent.type == 'doc.class'
@@ -264,7 +264,7 @@ local function getInfoFromDefs(defs)
return paramsTypes
end
-local function getArgsInfo(callArgs)
+local function getArgsInfo(uri, callArgs)
local callArgsType = {}
for _, arg in ipairs(callArgs) do
-- local defs = vm.getDefs(arg)
@@ -276,7 +276,7 @@ local function getArgsInfo(callArgs)
end
local hasAny = infers['any']
---处理继承
- addFatherClass(infers)
+ addFatherClass(uri, infers)
if not hasAny then
infers['any'] = nil
infers['unknown'] = nil
@@ -285,7 +285,7 @@ local function getArgsInfo(callArgs)
if not infers['table'] then
for k in pairs(infers) do
if not vm.isBuiltinType(k)
- and isUserDefineClass(k) then
+ and isUserDefineClass(uri, k) then
infers['table'] = true
break
end
@@ -424,7 +424,7 @@ return function (uri, callback)
end
await.delay()
local callArgs = source.args
- local suc, callArgsType = getArgsInfo(callArgs)
+ local suc, callArgsType = getArgsInfo(uri, callArgs)
if not suc then
return
end
diff --git a/script/core/diagnostics/undefined-doc-class.lua b/script/core/diagnostics/undefined-doc-class.lua
index e7133ab9..5f3902a2 100644
--- a/script/core/diagnostics/undefined-doc-class.lua
+++ b/script/core/diagnostics/undefined-doc-class.lua
@@ -25,7 +25,7 @@ return function (uri, callback)
end
for _, ext in ipairs(doc.extends) do
local name = ext[1]
- local docs = vm.getDocDefines(name)
+ local docs = vm.getDocDefines(uri, name)
if cache[name] == nil then
cache[name] = false
for _, otherDoc in ipairs(docs) do
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index 48c8a226..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 'Lua.diagnostics.globals'[key] then
+ if config.get(uri, 'Lua.diagnostics.globals')[key] then
return
end
- if config.get '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 06bbf421..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 'Lua.hint.paramType' then
+ if not config.get(uri, 'Lua.hint.paramType') then
return
end
else
- if not config.get '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 '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 '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 df9fb6e9..c46b239d 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -11,11 +11,11 @@ local guide = require 'parser.guide'
local noder = require 'core.noder'
local rpath = require 'workspace.require-path'
-local function collectRequire(mode, literal)
- local rootPath = ws.path or ''
+local function collectRequire(mode, literal, uri)
+ local rootPath = ws.getRootUri(uri) or ''
local result, searchers
if mode == 'require' then
- result, searchers = rpath.findUrisByRequirePath(literal)
+ result, searchers = rpath.findUrisByRequirePath(uri, literal)
elseif mode == 'dofile'
or mode == 'loadfile' then
result = ws.findUrisByFilePath(literal)
@@ -57,7 +57,7 @@ local function asStringInRequire(source, literal)
if libName == 'require'
or libName == 'dofile'
or libName == 'loadfile' then
- return collectRequire(libName, literal)
+ return collectRequire(libName, literal, guide.getUri(source))
end
end
end
@@ -65,11 +65,11 @@ end
local function asStringView(source, literal)
-- 内部包含转义符?
local rawLen = source.finish - source.start - 2 * #source[2]
- if config.get '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 'Lua.hover.viewStringMax'
+ local max = config.get(guide.getUri(source), 'Lua.hover.viewStringMax')
if #view > max then
view = view:sub(1, max) .. '...'
end
@@ -157,7 +157,7 @@ local function tryDocModule(source)
if not source.module then
return
end
- return collectRequire('require', source.module)
+ return collectRequire('require', source.module, guide.getUri(source))
end
local function buildEnumChunk(docType, name)
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 78756ea8..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 '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/return.lua b/script/core/hover/return.lua
index 49f9536a..681e9747 100644
--- a/script/core/hover/return.lua
+++ b/script/core/hover/return.lua
@@ -1,4 +1,5 @@
local infer = require 'core.infer'
+local guide = require 'parser.guide'
local function getReturnDualByDoc(source)
local docs = source.bindDocs
@@ -67,7 +68,7 @@ local function asFunction(source)
end
end
if next(infers) or rtn[1] then
- local tp = infer.viewInfers(infers)
+ local tp = infer.viewInfers(guide.getUri(source), infers)
if rtn[1].name then
line[#line+1] = ('%s%s: %s'):format(
rtn[1].name[1],
diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua
index 285d5c02..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 '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 d204fff1..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 '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 '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 dc846cf3..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 '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 '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 '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 '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/searcher.lua b/script/core/searcher.lua
index 72dda55f..558dc96b 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -27,6 +27,7 @@ local getUri = guide.getUri
local getRoot = guide.getRoot
local ceach = collector.each
+local ceachref = collector.eachRef
local getState = files.getState
@@ -796,7 +797,7 @@ function m.searchRefsByID(status, suri, expect, mode)
if not requireName then
return
end
- local uris = rpath.findUrisByRequirePath(requireName)
+ local uris = rpath.findUrisByRequirePath(suri, requireName)
footprint(status, 'require:', requireName)
for i = 1, #uris do
local ruri = uris[i]
@@ -820,7 +821,7 @@ function m.searchRefsByID(status, suri, expect, mode)
or mode == 'alldef'
or field
or hasCall(field) then
- for _, guri in ceach('def:' .. id) do
+ for _, guri in ceach(suri, 'def:' .. id) do
if uri == guri then
goto CONTINUE
end
@@ -829,14 +830,14 @@ function m.searchRefsByID(status, suri, expect, mode)
end
elseif mode == 'field'
or mode == 'allfield' then
- for _, guri in ceach('def:' .. id) do
+ for _, guri in ceach(suri, 'def:' .. id) do
if uri == guri then
goto CONTINUE
end
searchID(guri, id, field, uri)
::CONTINUE::
end
- for _, guri in ceach('field:' .. id) do
+ for _, guri in ceach(suri, 'field:' .. id) do
if uri == guri then
goto CONTINUE
end
@@ -844,7 +845,7 @@ function m.searchRefsByID(status, suri, expect, mode)
::CONTINUE::
end
else
- for _, guri in ceach(id) do
+ for _, guri in ceachref(suri, id) do
if crossed[guri] then
goto CONTINUE
end
@@ -872,7 +873,7 @@ function m.searchRefsByID(status, suri, expect, mode)
or ignoredIDs[id]
or id == 'dn:string'
or hasCall(field) then
- for _, guri in ceach('def:' .. id) do
+ for _, guri in ceach(suri, 'def:' .. id) do
if uri == guri then
goto CONTINUE
end
@@ -880,7 +881,7 @@ function m.searchRefsByID(status, suri, expect, mode)
::CONTINUE::
end
else
- for _, guri in ceach(id) do
+ for _, guri in ceachref(suri, id) do
if crossed[guri] then
goto CONTINUE
end
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index 8389cbb4..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 '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/core/type-definition.lua b/script/core/type-definition.lua
index e9cf3e47..1f021fb3 100644
--- a/script/core/type-definition.lua
+++ b/script/core/type-definition.lua
@@ -76,7 +76,7 @@ local function checkRequire(source, offset)
return nil
end
if libName == 'require' then
- return rpath.findUrisByRequirePath(literal)
+ return rpath.findUrisByRequirePath(guide.getUri(source), literal)
elseif libName == 'dofile'
or libName == 'loadfile' then
return workspace.findUrisByFilePath(literal)