diff options
author | Bruno Carvalho <b.camara@live.com> | 2024-04-23 13:28:07 -0300 |
---|---|---|
committer | Bruno Carvalho <b.camara@live.com> | 2024-04-23 13:28:07 -0300 |
commit | a8c0929405a02e54749d3d59ce4dad7bc3e0a863 (patch) | |
tree | 36e2be9dd50eb5a958c8803193b2be133a74c3d9 /script/core/diagnostics/lowercase-global.lua | |
parent | 6b5e19597d88a219aac73cbccd6f88a4213e07aa (diff) | |
download | lua-language-server-a8c0929405a02e54749d3d59ce4dad7bc3e0a863.zip |
Add globalsRegex to diagnostics
Improve checkIsUndefinedGlobal to avoid unecessary checks and tables
Diffstat (limited to 'script/core/diagnostics/lowercase-global.lua')
-rw-r--r-- | script/core/diagnostics/lowercase-global.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/script/core/diagnostics/lowercase-global.lua b/script/core/diagnostics/lowercase-global.lua index 68bec234..c7e9294d 100644 --- a/script/core/diagnostics/lowercase-global.lua +++ b/script/core/diagnostics/lowercase-global.lua @@ -17,6 +17,20 @@ local function isDocClass(source) return false end +local function isGlobalRegex(name, definedGlobalRegex) + if not definedGlobalRegex then + return false + end + + for _, pattern in ipairs(definedGlobalRegex) do + if name:match(pattern) then + return true + end + end + + return false +end + -- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删) return function (uri, callback) local ast = files.getState(uri) @@ -25,6 +39,7 @@ return function (uri, callback) end local definedGlobal = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals')) + local definedGlobalRegex = config.get(uri, 'Lua.diagnostics.globalsRegex') guide.eachSourceType(ast.ast, 'setglobal', function (source) local name = guide.getKeyName(source) @@ -42,6 +57,9 @@ return function (uri, callback) if isDocClass(source) then return end + if isGlobalRegex(name, definedGlobalRegex) then + return + end if definedGlobal[name] == nil then definedGlobal[name] = false local global = vm.getGlobal('variable', name) |