diff options
author | Sewbacca <sebastian.kalus@kolabnow.com> | 2023-07-17 14:34:49 +0200 |
---|---|---|
committer | Sewbacca <sebastian.kalus@kolabnow.com> | 2023-07-17 14:34:49 +0200 |
commit | 393f3e844d5164116de8bd739fc06d76bd03439f (patch) | |
tree | 2e1b514bdc38885623781089fba3ef327c76f39a /script/core/diagnostics/undefined-global.lua | |
parent | 62068c0709d2fd131607940852b0d938b43794b4 (diff) | |
download | lua-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.lua | 47 |
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 |