summaryrefslogtreecommitdiff
path: root/script/vm/global.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/global.lua')
-rw-r--r--script/vm/global.lua55
1 files changed, 47 insertions, 8 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index e830f6d8..aa987cf4 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -539,21 +539,60 @@ function vm.hasGlobalSets(suri, cate, name)
return true
end
+---@param uri uri
+---@param key string
+---@return boolean
+local function checkIsGlobalRegex(uri, key)
+ local dglobalsregex = config.get(uri, 'Lua.diagnostics.globalsRegex')
+ if not dglobalsregex then
+ return false
+ end
+
+ for _, pattern in ipairs(dglobalsregex) do
+ if key:match(pattern) then
+ return true
+ end
+ end
+
+ return false
+end
+
---@param src parser.object
local function checkIsUndefinedGlobal(src)
+ if src.type ~= 'getglobal' then
+ return false
+ end
+
local key = src[1]
+ if not key then
+ return false
+ end
+
+ local node = src.node
+ if node.tag ~= '_ENV' then
+ return false
+ end
local uri = guide.getUri(src)
- local dglobals = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
local rspecial = config.get(uri, 'Lua.runtime.special')
+ if rspecial[key] then
+ return false
+ end
- local node = src.node
- return src.type == 'getglobal' and key and not (
- dglobals[key] or
- rspecial[key] or
- node.tag ~= '_ENV' or
- vm.hasGlobalSets(uri, 'variable', key)
- )
+ if vm.hasGlobalSets(uri, 'variable', key) then
+ return false
+ end
+
+ local dglobals = config.get(uri, 'Lua.diagnostics.globals')
+ if util.arrayHas(dglobals, key) then
+ return false
+ end
+
+ if checkIsGlobalRegex(uri, key) then
+ return false
+ end
+
+ return true
end
---@param src parser.object