summaryrefslogtreecommitdiff
path: root/script/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-11 20:34:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-11 20:34:02 +0800
commit8f056d36ec61dd91cfab282780dc1786df646fcb (patch)
treee81ec976ad922c4bc74dedf29548f2a7c322f68e /script/core/diagnostics
parent3820962ca2d23d525bc8417c8088e7eeb667cba1 (diff)
downloadlua-language-server-8f056d36ec61dd91cfab282780dc1786df646fcb.zip
Revert "resolve #1209"
This reverts commit 3820962ca2d23d525bc8417c8088e7eeb667cba1.
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r--script/core/diagnostics/global-in-nil-env.lua68
-rw-r--r--script/core/diagnostics/undefined-env-child.lua32
-rw-r--r--script/core/diagnostics/undefined-global.lua6
3 files changed, 58 insertions, 48 deletions
diff --git a/script/core/diagnostics/global-in-nil-env.lua b/script/core/diagnostics/global-in-nil-env.lua
index e154080c..334fd81a 100644
--- a/script/core/diagnostics/global-in-nil-env.lua
+++ b/script/core/diagnostics/global-in-nil-env.lua
@@ -2,35 +2,65 @@ local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
+-- TODO: 检查路径是否可达
+local function mayRun(path)
+ return true
+end
+
return function (uri, callback)
- local state = files.getState(uri)
- if not state then
+ local ast = files.getState(uri)
+ if not ast then
+ return
+ end
+ local root = guide.getRoot(ast.ast)
+ local env = guide.getENV(root)
+
+ local nilDefs = {}
+ if not env or not env.ref then
+ return
+ end
+ for _, ref in ipairs(env.ref) do
+ if ref.type == 'setlocal' then
+ if ref.value and ref.value.type == 'nil' then
+ nilDefs[#nilDefs+1] = ref
+ end
+ end
+ end
+
+ if #nilDefs == 0 then
return
end
local function check(source)
local node = source.node
if node.tag == '_ENV' then
- return
- end
-
- if not node.value or node.value.type == 'nil' then
- callback {
- start = source.start,
- finish = source.finish,
- uri = uri,
- message = lang.script.DIAG_GLOBAL_IN_NIL_ENV,
- related = {
- {
- start = node.start,
- finish = node.finish,
- uri = uri,
+ local ok
+ for _, nilDef in ipairs(nilDefs) do
+ local mode, pathA = guide.getPath(nilDef, source)
+ if mode == 'before'
+ and mayRun(pathA) then
+ ok = nilDef
+ break
+ end
+ end
+ if ok then
+ callback {
+ start = source.start,
+ finish = source.finish,
+ uri = uri,
+ message = lang.script.DIAG_GLOBAL_IN_NIL_ENV,
+ related = {
+ {
+ start = ok.start,
+ finish = ok.finish,
+ uri = uri,
+ }
}
}
- }
+ end
end
end
- guide.eachSourceType(state.ast, 'getglobal', check)
- guide.eachSourceType(state.ast, 'setglobal', check)
+ guide.eachSourceType(ast.ast, 'getglobal', check)
+ guide.eachSourceType(ast.ast, 'setglobal', check)
end
diff --git a/script/core/diagnostics/undefined-env-child.lua b/script/core/diagnostics/undefined-env-child.lua
index 1dff575b..2f559697 100644
--- a/script/core/diagnostics/undefined-env-child.lua
+++ b/script/core/diagnostics/undefined-env-child.lua
@@ -3,40 +3,20 @@ local guide = require 'parser.guide'
local lang = require 'language'
local vm = require "vm.vm"
----@param source parser.object
----@return boolean
-local function isBindDoc(source)
- if not source.bindDocs then
- return false
- end
- for _, doc in ipairs(source.bindDocs) do
- if doc.type == 'doc.type'
- or doc.type == 'doc.class' then
- return true
- end
- end
- return false
-end
-
return function (uri, callback)
- local state = files.getState(uri)
- if not state then
+ local ast = files.getState(uri)
+ if not ast then
return
end
-
- guide.eachSourceType(state.ast, 'getglobal', function (source)
+ guide.eachSourceType(ast.ast, 'getglobal', function (source)
+ -- 单独验证自己是否在重载过的 _ENV 中有定义
if source.node.tag == '_ENV' then
return
end
-
- if not isBindDoc(source.node) then
+ local defs = vm.getDefs(source)
+ if #defs > 0 then
return
end
-
- if #vm.getDefs(source) > 0 then
- return
- end
-
local key = source[1]
callback {
start = source.start,
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index 179c9204..bf161c73 100644
--- a/script/core/diagnostics/undefined-global.lua
+++ b/script/core/diagnostics/undefined-global.lua
@@ -15,8 +15,8 @@ local requireLike = {
---@async
return function (uri, callback)
- local state = files.getState(uri)
- if not state then
+ local ast = files.getState(uri)
+ if not ast then
return
end
@@ -25,7 +25,7 @@ return function (uri, callback)
local cache = {}
-- 遍历全局变量,检查所有没有 set 模式的全局变量
- guide.eachSourceType(state.ast, 'getglobal', function (src) ---@async
+ guide.eachSourceType(ast.ast, 'getglobal', function (src) ---@async
local key = src[1]
if not key then
return