diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-29 15:40:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-29 15:40:34 +0800 |
commit | 91242c007da6279443b84cd9a3052adeca6ea312 (patch) | |
tree | e5ea739b1ba9938fae0ddfd0b22ced941af9b46d /server/src | |
parent | 1a1d1ce6c259814eb276567450be0d05853cbc56 (diff) | |
download | lua-language-server-91242c007da6279443b84cd9a3052adeca6ea312.zip |
由于编译循环的问题,必须在外部获取全局环境
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/diagnostics.lua | 33 |
1 files changed, 21 insertions, 12 deletions
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) |