summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/core/diagnostics.lua35
-rw-r--r--server/src/vm/source.lua2
-rw-r--r--server/test/diagnostics/init.lua18
3 files changed, 48 insertions, 7 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index e6ba6f83..f2e2d1f7 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -1,5 +1,6 @@
local lang = require 'language'
local config = require 'config'
+local library = require 'core.library'
local DiagnosticSeverity = {
Error = 1,
@@ -248,6 +249,33 @@ function mt:searchAmbiguity1(callback)
end)
end
+function mt:searchLowercaseGlobal(callback)
+ local definedGlobal = {}
+ for name in pairs(config.config.diagnostics.globals) do
+ definedGlobal[name] = true
+ end
+ for name in pairs(library.global) do
+ definedGlobal[name] = true
+ end
+ local uri = self.vm.uri
+ local envValue = self.vm.env:getValue()
+ envValue:eachInfo(function (info, src)
+ if info.type == 'set child' and src.uri == uri then
+ local name = info[1]
+ if definedGlobal[name] then
+ return
+ end
+ local first = name:match '%w'
+ if not first then
+ return
+ end
+ if first:match '%l' then
+ callback(src.start, src.finish)
+ end
+ end
+ end)
+end
+
function mt:doDiagnostics(func, code, callback)
if config.config.diagnostics.disable[code] then
return
@@ -333,5 +361,12 @@ return function (vm, lines, uri)
message = lang.script('DIAG_AMBIGUITY_1', op, num),
}
end)
+ -- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删)
+ session:doDiagnostics(session.searchLowercaseGlobal, 'lowercase-global', function ()
+ return {
+ level = DiagnosticSeverity.Information,
+ message = '首字母小写的全局变量',
+ }
+ end)
return session.datas
end
diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua
index 8de44b1b..c364d9cf 100644
--- a/server/src/vm/source.lua
+++ b/server/src/vm/source.lua
@@ -2,7 +2,7 @@ local listMgr = require 'vm.list'
local mt = {}
mt.__index = mt
-mt.uri = ''
+mt.uri = '@dummy'
mt.start = 0
mt.finish = 0
mt.id = 0
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index c9a8a95d..7bba139d 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -72,8 +72,8 @@ print(<!X!>)
print(<!Log!>)
print(_VERSION)
print(<!y!>)
-print(z)
-z = 1
+print(Z)
+Z = 1
]]
TEST [[
@@ -85,11 +85,11 @@ TEST [[
]]
TEST [[
-x = 1<! !>
+X = 1<! !>
]]
TEST [[
-x = [=[
+X = [=[
]=]
]]
@@ -136,8 +136,8 @@ x(1, 2, <!3!>)
]]
TEST [[
-instanceName = 1
-instance = _G[instanceName]
+InstanceName = 1
+Instance = _G[InstanceName]
]]
TEST [[
@@ -230,3 +230,9 @@ tostring(<!1!>)
tostring = realTostring
tostring(1)
]]
+
+TEST [[
+<!aa!> = 1
+tostring = 1
+ROOT = 1
+]]