summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/undefined-global.lua
diff options
context:
space:
mode:
authorSewbacca <sebastian.kalus@kolabnow.com>2023-07-17 14:34:49 +0200
committerSewbacca <sebastian.kalus@kolabnow.com>2023-07-17 14:34:49 +0200
commit393f3e844d5164116de8bd739fc06d76bd03439f (patch)
tree2e1b514bdc38885623781089fba3ef327c76f39a /script/core/diagnostics/undefined-global.lua
parent62068c0709d2fd131607940852b0d938b43794b4 (diff)
downloadlua-language-server-393f3e844d5164116de8bd739fc06d76bd03439f.zip
Extracted undefined global check
Diffstat (limited to 'script/core/diagnostics/undefined-global.lua')
-rw-r--r--script/core/diagnostics/undefined-global.lua47
1 files changed, 13 insertions, 34 deletions
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index 87501277..d9d94959 100644
--- a/script/core/diagnostics/undefined-global.lua
+++ b/script/core/diagnostics/undefined-global.lua
@@ -20,42 +20,21 @@ return function (uri, callback)
return
end
- local dglobals = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
- local rspecial = config.get(uri, 'Lua.runtime.special')
- local cache = {}
-
-- 遍历全局变量,检查所有没有 set 模式的全局变量
guide.eachSourceType(state.ast, 'getglobal', function (src) ---@async
- local key = src[1]
- if not key then
- return
- end
- if dglobals[key] then
- return
- end
- if rspecial[key] then
- return
- end
- local node = src.node
- if node.tag ~= '_ENV' then
- return
- end
- if cache[key] == nil then
- await.delay()
- cache[key] = vm.hasGlobalSets(uri, 'variable', key)
- end
- if cache[key] then
- return
- end
- local message = lang.script('DIAG_UNDEF_GLOBAL', key)
- if requireLike[key:lower()] then
- message = ('%s(%s)'):format(message, lang.script('DIAG_REQUIRE_LIKE', key))
+ if vm.isUndefinedGlobal(src) then
+ local key = src[1]
+ local message = lang.script('DIAG_UNDEF_GLOBAL', key)
+ if requireLike[key:lower()] then
+ message = ('%s(%s)'):format(message, lang.script('DIAG_REQUIRE_LIKE', key))
+ end
+
+ callback {
+ start = src.start,
+ finish = src.finish,
+ message = message,
+ undefinedGlobal = src[1]
+ }
end
- callback {
- start = src.start,
- finish = src.finish,
- message = message,
- undefinedGlobal = src[1]
- }
end)
end