diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-04 18:22:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-04 18:22:51 +0800 |
commit | 521feda953a686ad876186366391340f945ca65b (patch) | |
tree | dbda5f79ce6cf55b882b01b10f08fd2638c93de1 /server-beta/src/core/diagnostics/undefined-global.lua | |
parent | 137ede024f4ddeac7c602351371447cd6cf36091 (diff) | |
download | lua-language-server-521feda953a686ad876186366391340f945ca65b.zip |
更新诊断实现
Diffstat (limited to 'server-beta/src/core/diagnostics/undefined-global.lua')
-rw-r--r-- | server-beta/src/core/diagnostics/undefined-global.lua | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua index b3d19c21..db7af133 100644 --- a/server-beta/src/core/diagnostics/undefined-global.lua +++ b/server-beta/src/core/diagnostics/undefined-global.lua @@ -1,3 +1,36 @@ -return function () - +local files = require 'files' +local guide = require 'parser.guide' +local searcher = require 'searcher' +local define = require 'proto.define' +local lang = require 'language' + +return function (uri, callback) + local ast = files.getAst(uri) + if not ast then + return + end + + local hasSet = {} + searcher.eachGlobal(ast.ast, function (info) + local key = info.key + if hasSet[key] ~= nil then + return + end + hasSet[key] = false + searcher.eachRef(info.source, function (info) + if info.mode == 'set' then + hasSet[key] = true + end + end) + end) + searcher.eachGlobal(ast.ast, function (info) + local source = info.source + if info.mode == 'get' and not hasSet[info.key] then + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_UNDEF_GLOBAL', info.key), + } + end + end) end |