From 91242c007da6279443b84cd9a3052adeca6ea312 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 15:40:34 +0800 Subject: =?UTF-8?q?=E7=94=B1=E4=BA=8E=E7=BC=96=E8=AF=91=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=BF=85=E9=A1=BB=E5=9C=A8?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E8=8E=B7=E5=8F=96=E5=85=A8=E5=B1=80=E7=8E=AF?= =?UTF-8?q?=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/diagnostics.lua | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'server/src') diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 84d3578c..a5ede80e 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -1,6 +1,7 @@ local lang = require 'language' local config = require 'config' local library = require 'core.library' +local buildGlobal = require 'vm.global' local DiagnosticSeverity = { Error = 1, @@ -44,6 +45,13 @@ function mt:searchUndefinedGlobal(callback) for name in pairs(config.config.diagnostics.globals) do definedGlobal[name] = true end + local envValue = buildGlobal(self.vm.lsp) + envValue:eachInfo(function (info) + if info.type == 'set child' then + local name = info[1] + definedGlobal[name] = true + end + end) self.vm:eachSource(function (source) if not source:get 'global' then return @@ -56,22 +64,23 @@ function mt:searchUndefinedGlobal(callback) if not value then return end - if definedGlobal[name] then + 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) return end - local parent = source:get 'parent' - if not parent then + if definedGlobal[name] then return end - local ok = parent:eachInfo(function (info, src) - if info.type == 'set child' and info[1] == name then - return true - end - if src == source then - return false - end - end) - if ok then + if type(name) ~= 'string' then return end callback(source.start, source.finish, name) -- cgit v1.2.3