summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-29 15:28:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-29 15:28:02 +0800
commit1a1d1ce6c259814eb276567450be0d05853cbc56 (patch)
tree93162fb19e9668cd88fbe9160592c18ab1ecf006 /server
parentc0f1352581b5a4b046fc775c066feacf576156ba (diff)
downloadlua-language-server-1a1d1ce6c259814eb276567450be0d05853cbc56.zip
修正未定义全局变量找的不正确的问题
Diffstat (limited to 'server')
-rw-r--r--server/src/core/diagnostics.lua32
-rw-r--r--server/test/diagnostics/init.lua7
2 files changed, 18 insertions, 21 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index ff030348..84d3578c 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -44,13 +44,6 @@ function mt:searchUndefinedGlobal(callback)
for name in pairs(config.config.diagnostics.globals) do
definedGlobal[name] = true
end
- local envValue = self.vm.env:getValue()
- 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
@@ -63,23 +56,22 @@ function mt:searchUndefinedGlobal(callback)
if not value 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 definedGlobal[name] then
return
end
- if definedGlobal[name] then
+ local parent = source:get 'parent'
+ if not parent then
return
end
- if type(name) ~= 'string' then
+ 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
return
end
callback(source.start, source.finish, name)
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index 7bba139d..a6dc6d93 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
]]
@@ -119,6 +119,11 @@ local _ENV
]]
TEST [[
+print(1)
+_ENV = nil
+]]
+
+TEST [[
print()
<!('string')!>:sub(1, 1)
]]