From 8b0c14300059fa949b6d8fe5d95305c8be5ccd60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 29 Mar 2019 16:22:02 +0800 Subject: =?UTF-8?q?=E9=87=8D=E8=BD=BD=E5=8F=98=E9=87=8F=E6=9C=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/diagnostics.lua | 51 ++++++++++++++++++++++++++++++----------- server/src/vm/global.lua | 1 + 2 files changed, 38 insertions(+), 14 deletions(-) (limited to 'server/src') diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index d541e8de..72bcdbe4 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -60,21 +60,11 @@ function mt:searchUndefinedGlobal(callback) if name == '' then return end - local value = source:bindValue() - if not value then + local parent = source:get 'parent' + if not parent then return end - if not value:isGlobal() then - -- 上文重载了 _ENV 的情况 - local ok = value:eachInfo(function (info) - if info.type == 'set' then - return true - end - end) - if ok then - return - end - callback(source.start, source.finish, name) + if not parent:get 'ENV' then return end if definedGlobal[name] then @@ -296,6 +286,32 @@ function mt:doDiagnostics(func, code, callback) end end +function mt:searchUndefinedEnvChild(callback) + self.vm:eachSource(function (source) + if not source:get 'global' then + return + end + local name = source:getName() + if name == '' then + return + end + local parent = source:get 'parent' + if parent:get 'ENV' then + return + end + local ok = parent:eachInfo(function (info) + if info.type == 'set child' and info[1] == name then + return true + end + end) + if ok then + return + end + callback(source.start, source.finish, name) + return + end) +end + return function (vm, lines, uri) local session = setmetatable({ vm = vm, @@ -315,7 +331,7 @@ return function (vm, lines, uri) session:doDiagnostics(session.searchUndefinedGlobal, 'undefined-global', function (key) return { level = DiagnosticSeverity.Warning, - message = lang.script('DIAG_UNDEFINED_GLOBAL', key), + message = lang.script('DIAG_UNDEF_GLOBAL', key), } end) -- 未使用的Label @@ -368,5 +384,12 @@ return function (vm, lines, uri) message = lang.script.DIAG_LOWERCASE_GLOBAL, } end) + -- 未定义的变量(重载了 `_ENV`) + session:doDiagnostics(session.searchUndefinedEnvChild, 'undefined-env-child', function (key) + return { + level = DiagnosticSeverity.Information, + message = lang.script('DIAG_UNDEF_ENV_CHILD', key), + } + end) return session.datas end diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua index 54680fd3..af30ffdd 100644 --- a/server/src/vm/global.lua +++ b/server/src/vm/global.lua @@ -13,6 +13,7 @@ return function (lsp) global = t._G global:markGlobal() + global:set('ENV', true) for k, v in pairs(t) do global:setChild(k, v, sourceMgr.dummy()) end -- cgit v1.2.3