summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-29 15:40:34 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-29 15:40:34 +0800
commit91242c007da6279443b84cd9a3052adeca6ea312 (patch)
treee5ea739b1ba9938fae0ddfd0b22ced941af9b46d /server
parent1a1d1ce6c259814eb276567450be0d05853cbc56 (diff)
downloadlua-language-server-91242c007da6279443b84cd9a3052adeca6ea312.zip
由于编译循环的问题,必须在外部获取全局环境
Diffstat (limited to 'server')
-rw-r--r--server/src/core/diagnostics.lua33
-rw-r--r--server/test/diagnostics/init.lua2
2 files changed, 22 insertions, 13 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)
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index a6dc6d93..8c7c624d 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -72,7 +72,7 @@ print(<!X!>)
print(<!Log!>)
print(_VERSION)
print(<!y!>)
-print(<!Z!>)
+print(Z)
Z = 1
]]