diff options
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/core/diagnostics/undefined-global.lua | 17 | ||||
-rw-r--r-- | server-beta/src/files.lua | 21 | ||||
-rw-r--r-- | server-beta/src/searcher/eachRef.lua | 18 |
3 files changed, 46 insertions, 10 deletions
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua index 1a0af9d9..921ba086 100644 --- a/server-beta/src/core/diagnostics/undefined-global.lua +++ b/server-beta/src/core/diagnostics/undefined-global.lua @@ -10,12 +10,17 @@ return function (uri, callback) return end + local globalCache = {} + -- 遍历全局变量,检查所有没有 mode['set'] 的全局变量 local globals = searcher.getGlobals(ast.ast) for key, infos in pairs(globals) do if infos.mode['set'] == true then goto CONTINUE end + if globalCache[key] then + goto CONTINUE + end local skey = key and key:match '^s|(.+)$' if not skey then goto CONTINUE @@ -26,6 +31,18 @@ return function (uri, callback) if config.config.diagnostics.globals[skey] then goto CONTINUE end + if globalCache[key] == nil then + local uris = files.findGlobals(key) + for i = 1, #uris do + local destAst = files.getAst(uris[i]) + local destGlobals = searcher.getGlobals(destAst.ast) + if destGlobals[key] and destGlobals[key].mode['set'] then + globalCache[key] = true + goto CONTINUE + end + end + end + globalCache[key] = false local message local otherVersion = library.other[skey] local customVersion = library.custom[skey] diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua index 8a362841..a9b833b2 100644 --- a/server-beta/src/files.lua +++ b/server-beta/src/files.lua @@ -213,6 +213,27 @@ function m.getGlobals(uri) return file.globals end +--- 寻找全局变量 +function m.findGlobals(name) + local uris = {} + for uri, file in pairs(m.fileMap) do + if not file.globals then + local ast = m.getAst(uri) + if ast then + file.globals = {} + local globals = searcher.getGlobals(ast.ast) + for name in pairs(globals) do + file.globals[name] = true + end + end + end + if file.globals[name] then + uris[#uris+1] = file.uri + end + end + return uris +end + --- 判断文件名相等 function m.eq(a, b) if platform.OS == 'Windows' then diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua index dca1c636..b1023f52 100644 --- a/server-beta/src/searcher/eachRef.lua +++ b/server-beta/src/searcher/eachRef.lua @@ -234,17 +234,15 @@ local function ofGlobal(source, callback) local key = guide.getKeyName(source) local node = source.node if node.tag == '_ENV' then - for uri in files.eachFile() do - local globals = files.getGlobals(uri) + local uris = files.findGlobals(key) + for _, uri in ipairs(uris) do local ast = files.getAst(uri) - if ast and globals and globals[key] then - globals = searcher.getGlobals(ast.ast) - if globals[key] then - for _, info in ipairs(globals[key]) do - callback(info) - if info.value then - ofValue(info.value, callback) - end + local globals = searcher.getGlobals(ast.ast) + if globals[key] then + for _, info in ipairs(globals[key]) do + callback(info) + if info.value then + ofValue(info.value, callback) end end end |