diff options
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/diagnostics/undefined-env-child.lua | 10 | ||||
-rw-r--r-- | script-beta/core/diagnostics/undefined-global.lua | 78 |
2 files changed, 26 insertions, 62 deletions
diff --git a/script-beta/core/diagnostics/undefined-env-child.lua b/script-beta/core/diagnostics/undefined-env-child.lua index a19abb63..6b8c62f0 100644 --- a/script-beta/core/diagnostics/undefined-env-child.lua +++ b/script-beta/core/diagnostics/undefined-env-child.lua @@ -8,19 +8,13 @@ return function (uri, callback) if not ast then return end - -- 再遍历一次 getglobal ,找出 _ENV 被重载的情况 guide.eachSourceType(ast.ast, 'getglobal', function (source) -- 单独验证自己是否在重载过的 _ENV 中有定义 if source.node.tag == '_ENV' then return end - local setInENV - vm.eachRef(source, function (src) - if vm.isSet(src) then - setInENV = true - end - end) - if setInENV then + local defs = guide.requestDefinition(source) + if #defs > 0 then return end local key = source[1] diff --git a/script-beta/core/diagnostics/undefined-global.lua b/script-beta/core/diagnostics/undefined-global.lua index 4cb9c1ef..3a9aa554 100644 --- a/script-beta/core/diagnostics/undefined-global.lua +++ b/script-beta/core/diagnostics/undefined-global.lua @@ -3,19 +3,7 @@ local vm = require 'vm' local lang = require 'language' local library = require 'library' local config = require 'config' - -local function hasSet(sources) - if sources.hasSet ~= nil then - return sources.hasSet - end - sources.hasSet = false - for i = 1, #sources do - if vm.isSet(sources[i]) then - sources.hasSet = true - end - end - return sources.hasSet -end +local guide = require 'parser.guide' return function (uri, callback) local ast = files.getAst(uri) @@ -24,56 +12,38 @@ return function (uri, callback) end local globalCache = {} - -- 遍历全局变量,检查所有没有 set 模式的全局变量 - local globals = vm.getGlobals(ast.ast) - if not globals then - return - end - for key, sources in pairs(globals) do - if hasSet(sources) then - goto CONTINUE + guide.eachSourceType(ast.ast, 'getglobal', function (src) + local key = guide.getName(src) + if not key then + return end - if globalCache[key] then - goto CONTINUE + if globalCache[key] == nil then + local defs = guide.requestDefinition(src) + -- 这里要处理跨文件的情况 + globalCache[key] = #defs > 0 end - local skey = key and key:match '^s|(.+)$' - if not skey then - goto CONTINUE + if globalCache[key] then + return end - if library.global[skey] then - goto CONTINUE + if library.global[key] then + return end - if config.config.diagnostics.globals[skey] then - goto CONTINUE + if config.config.diagnostics.globals[key] then + return end - if globalCache[key] == nil then - local uris = files.findGlobals(key) - for i = 1, #uris do - local destAst = files.getAst(uris[i]) - local destGlobals = vm.getGlobals(destAst.ast) - if destGlobals[key] and hasSet(destGlobals[key]) then - globalCache[key] = true - goto CONTINUE - end - end - end - globalCache[key] = false - local message = lang.script('DIAG_UNDEF_GLOBAL', skey) - local otherVersion = library.other[skey] - local customVersion = library.custom[skey] + local message = lang.script('DIAG_UNDEF_GLOBAL', key) + local otherVersion = library.other[key] + local customVersion = library.custom[key] if otherVersion then message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/'), config.config.runtime.version)) elseif customVersion then message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/'))) end - for _, source in ipairs(sources) do - callback { - start = source.start, - finish = source.finish, - message = message, - } - end - ::CONTINUE:: - end + callback { + start = src.start, + finish = src.finish, + message = message, + } + end) end |