From cef2f9749c982d588eca71cdee8aed582b92539e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 5 Nov 2019 13:24:19 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=8A=E6=96=AD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/core/diagnostics/undefined-global.lua | 12 ++++++++++++ server-beta/src/core/diagnostics/unused-function.lua | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'server-beta/src/core') 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, -- cgit v1.2.3