diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-05 13:24:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-05 13:24:19 +0800 |
commit | cef2f9749c982d588eca71cdee8aed582b92539e (patch) | |
tree | 5c6a825ec8df689eede47f9579a8e2d26fbf2973 /server-beta/src/core | |
parent | 9b7a246d397aff61bc29837c40a1317ff18c7887 (diff) | |
download | lua-language-server-cef2f9749c982d588eca71cdee8aed582b92539e.zip |
更新诊断实现
Diffstat (limited to 'server-beta/src/core')
-rw-r--r-- | server-beta/src/core/diagnostics/undefined-global.lua | 12 | ||||
-rw-r--r-- | server-beta/src/core/diagnostics/unused-function.lua | 8 |
2 files changed, 18 insertions, 2 deletions
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua index 6c9abaca..ec796086 100644 --- a/server-beta/src/core/diagnostics/undefined-global.lua +++ b/server-beta/src/core/diagnostics/undefined-global.lua @@ -3,6 +3,7 @@ local searcher = require 'searcher' local lang = require 'language' local library = require 'library' local config = require 'config' +local guide = require 'parser.guide' return function (uri, callback) local ast = files.getAst(uri) @@ -60,4 +61,15 @@ return function (uri, callback) } end end) + -- 再遍历一次 getglobal ,找出 _ENV 被重载的情况 + guide.eachSourceType(ast.ast, 'getglobal', function (source) + if hasSet[source] == nil then + local key = source[1] + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_UNDEF_ENV_CHILD', key), + } + end + end) end diff --git a/server-beta/src/core/diagnostics/unused-function.lua b/server-beta/src/core/diagnostics/unused-function.lua index 80123948..0886660d 100644 --- a/server-beta/src/core/diagnostics/unused-function.lua +++ b/server-beta/src/core/diagnostics/unused-function.lua @@ -11,12 +11,16 @@ return function (uri, callback) end guide.eachSourceType(ast.ast, 'function', function (source) local hasGet + local hasSet searcher.eachRef(source, function (info) - if info.mode == 'get' then + if info.mode == 'get' then hasGet = true + elseif info.mode == 'set' + or info.mode == 'declare' then + hasSet = true end end) - if not hasGet then + if not hasGet and hasSet then callback { start = source.start, finish = source.finish, |