summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/main.lua2
-rw-r--r--server/src/core/diagnostics.lua32
-rw-r--r--server/src/vm/vm.lua6
-rw-r--r--server/test/diagnostics/init.lua33
4 files changed, 70 insertions, 3 deletions
diff --git a/server/main.lua b/server/main.lua
index ac7860c5..685fce01 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -22,7 +22,7 @@ local function tryDebugger()
log.info('Debugger startup, listen port: 11411')
end
---pcall(tryDebugger)
+pcall(tryDebugger)
require 'utility'
require 'global_protect'
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 7f47b548..1fdcac37 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -322,6 +322,31 @@ function mt:searchDuplicateIndex(callback)
end)
end
+function mt:searchEmptyBlock(callback)
+ self.vm:eachSource(function (source)
+ -- 认为空repeat是合法的
+ -- 要去vm中激活source
+ if source.type == 'if' then
+ for _, block in ipairs(source) do
+ if #block > 0 then
+ return
+ end
+ end
+ callback(source.start, source.finish)
+ return
+ end
+ if source.type == 'loop'
+ or source.type == 'in'
+ or source.type == 'while'
+ then
+ if #source == 0 then
+ callback(source.start, source.finish)
+ end
+ return
+ end
+ end)
+end
+
function mt:doDiagnostics(func, code, callback)
if config.config.diagnostics.disable[code] then
return
@@ -472,5 +497,12 @@ return function (vm, lines, uri)
related = related,
}
end)
+ -- 空代码块
+ session:doDiagnostics(session.searchEmptyBlock, 'empty-block', function ()
+ return {
+ level = DiagnosticSeverity.Information,
+ message = lang.script.DIAG_EMPTY_BLOCK,
+ }
+ end)
return session.datas
end
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index cd24f1ad..ef3ce27b 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -851,6 +851,7 @@ function mt:doLocal(action)
end
function mt:doIf(action)
+ self:instantSource(action)
for _, block in ipairs(action) do
if block.filter then
self:getExp(block.filter)
@@ -863,7 +864,7 @@ function mt:doIf(action)
end
function mt:doLoop(action)
-
+ self:instantSource(action)
local min = self:getFirstInMulti(self:getExp(action.min))
self:getExp(action.max)
if action.step then
@@ -877,6 +878,7 @@ function mt:doLoop(action)
end
function mt:doIn(action)
+ self:instantSource(action)
local args = self:unpackList(action.exp)
self:scopePush(action)
@@ -893,7 +895,7 @@ function mt:doIn(action)
end
function mt:doWhile(action)
-
+ self:instantSource(action)
self:getExp(action.filter)
self:scopePush(action)
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index e23e2b1a..365b2732 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -271,3 +271,36 @@ end
m:open()
]]
+
+TEST [[
+<!if true then
+end!>
+]]
+
+TEST [[
+<!if true then
+else
+end!>
+]]
+
+TEST [[
+if true then
+else
+ return
+end
+]]
+
+TEST [[
+<!while true do
+end!>
+]]
+
+TEST [[
+<!for _ = 1, 10 do
+end!>
+]]
+
+TEST [[
+<!for _ in pairs(_VERSION) do
+end!>
+]]