summaryrefslogtreecommitdiff
path: root/script-beta/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-10 12:02:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-10 12:02:43 +0800
commite1fac82828bedc20c123b0eb88f34223252db3b4 (patch)
treee4f4b3a9446019228a65d1d6ac985f285b849119 /script-beta/core/diagnostics
parent585dac714a2f6f197035e40701201d4f2474f616 (diff)
downloadlua-language-server-e1fac82828bedc20c123b0eb88f34223252db3b4.zip
诊断允许定义为 doc.class 的全局变量
Diffstat (limited to 'script-beta/core/diagnostics')
-rw-r--r--script-beta/core/diagnostics/lowercase-global.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/script-beta/core/diagnostics/lowercase-global.lua b/script-beta/core/diagnostics/lowercase-global.lua
index bc48e1e6..c7e459cc 100644
--- a/script-beta/core/diagnostics/lowercase-global.lua
+++ b/script-beta/core/diagnostics/lowercase-global.lua
@@ -4,6 +4,18 @@ local lang = require 'language'
local config = require 'config'
local library = require 'library'
+local function isDocClass(source)
+ if not source.bindDocs then
+ return false
+ end
+ for _, doc in ipairs(source.bindDocs) do
+ if doc.type == 'doc.class' then
+ return true
+ end
+ end
+ return false
+end
+
-- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删)
return function (uri, callback)
local ast = files.getAst(uri)
@@ -28,12 +40,17 @@ return function (uri, callback)
if not first then
return
end
- if first:match '%l' then
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script.DIAG_LOWERCASE_GLOBAL,
- }
+ if not first:match '%l' then
+ return
+ end
+ -- 如果赋值被标记为 doc.class ,则认为是允许的
+ if isDocClass(source) then
+ return
end
+ callback {
+ start = source.start,
+ finish = source.finish,
+ message = lang.script.DIAG_LOWERCASE_GLOBAL,
+ }
end)
end