summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-17 10:58:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-17 10:58:44 +0800
commit23411c384b049f015d4f7d80409125894a9e2d96 (patch)
tree9e382cc9c422090921260f710442e79dac71d6ac /server/src/core
parent1e712c3659d492c8a6c1eb8a92a0f042af7eb6e7 (diff)
downloadlua-language-server-23411c384b049f015d4f7d80409125894a9e2d96.zip
_ENV置为nil后的全局变量诊断
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/diagnostics.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 509fe48c..0e0d85ba 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -553,6 +553,29 @@ function mt:searchUndefinedEnvChild(callback)
end)
end
+function mt:searchGlobalInNilEnv(callback)
+ self.vm:eachSource(function (source)
+ if not source:get 'global' then
+ return
+ end
+ local name = source:getName()
+ if name == '' then
+ return
+ end
+ local parentSource = source:get 'parent' :getSource()
+ if parentSource.type == 'nil' then
+ callback(source.start, source.finish, {
+ {
+ start = parentSource.start,
+ finish = parentSource.finish,
+ uri = self.uri,
+ }
+ })
+ end
+ return
+ end)
+end
+
function mt:checkEmmyClass(source, callback)
local class = source:get 'emmy.class'
if not class then
@@ -919,6 +942,20 @@ return function (vm, lines, uri)
}
end
end)
+ -- 全局变量不可用(置空了 `_ENV`)
+ session:doDiagnostics(session.searchGlobalInNilEnv, 'global-in-nil-env', function (related)
+ if vm.envType == '_ENV' then
+ return {
+ message = lang.script.DIAG_GLOBAL_IN_NIL_ENV,
+ related = related,
+ }
+ else
+ return {
+ message = lang.script.DIAG_GLOBAL_IN_NIL_FENV,
+ related = related,
+ }
+ end
+ end)
-- 构建表时重复定义field
session:doDiagnostics(session.searchDuplicateIndex, 'duplicate-index', function (key, related, type)
if type == 'unused' then