summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-29 16:22:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-29 16:22:02 +0800
commit8b0c14300059fa949b6d8fe5d95305c8be5ccd60 (patch)
treef594756f9a25fcdfa0a5926f7e49c3be282d5d46 /server/src
parent4b96bc247b4b345757e43bb54451b482d7bfd5bc (diff)
downloadlua-language-server-8b0c14300059fa949b6d8fe5d95305c8be5ccd60.zip
重载变量未定义的诊断
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/diagnostics.lua51
-rw-r--r--server/src/vm/global.lua1
2 files changed, 38 insertions, 14 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index d541e8de..72bcdbe4 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -60,21 +60,11 @@ function mt:searchUndefinedGlobal(callback)
if name == '' then
return
end
- local value = source:bindValue()
- if not value then
+ local parent = source:get 'parent'
+ if not parent 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 not parent:get 'ENV' then
return
end
if definedGlobal[name] then
@@ -296,6 +286,32 @@ function mt:doDiagnostics(func, code, callback)
end
end
+function mt:searchUndefinedEnvChild(callback)
+ self.vm:eachSource(function (source)
+ if not source:get 'global' then
+ return
+ end
+ local name = source:getName()
+ if name == '' then
+ return
+ end
+ local parent = source:get 'parent'
+ if parent:get 'ENV' then
+ return
+ end
+ local ok = parent:eachInfo(function (info)
+ if info.type == 'set child' and info[1] == name then
+ return true
+ end
+ end)
+ if ok then
+ return
+ end
+ callback(source.start, source.finish, name)
+ return
+ end)
+end
+
return function (vm, lines, uri)
local session = setmetatable({
vm = vm,
@@ -315,7 +331,7 @@ return function (vm, lines, uri)
session:doDiagnostics(session.searchUndefinedGlobal, 'undefined-global', function (key)
return {
level = DiagnosticSeverity.Warning,
- message = lang.script('DIAG_UNDEFINED_GLOBAL', key),
+ message = lang.script('DIAG_UNDEF_GLOBAL', key),
}
end)
-- 未使用的Label
@@ -368,5 +384,12 @@ return function (vm, lines, uri)
message = lang.script.DIAG_LOWERCASE_GLOBAL,
}
end)
+ -- 未定义的变量(重载了 `_ENV`)
+ session:doDiagnostics(session.searchUndefinedEnvChild, 'undefined-env-child', function (key)
+ return {
+ level = DiagnosticSeverity.Information,
+ message = lang.script('DIAG_UNDEF_ENV_CHILD', key),
+ }
+ end)
return session.datas
end
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua
index 54680fd3..af30ffdd 100644
--- a/server/src/vm/global.lua
+++ b/server/src/vm/global.lua
@@ -13,6 +13,7 @@ return function (lsp)
global = t._G
global:markGlobal()
+ global:set('ENV', true)
for k, v in pairs(t) do
global:setChild(k, v, sourceMgr.dummy())
end