diff options
-rw-r--r-- | server/src/matcher/diagnostics.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua index 94dbebc2..da2d5c0a 100644 --- a/server/src/matcher/diagnostics.lua +++ b/server/src/matcher/diagnostics.lua @@ -53,6 +53,22 @@ local function searchUndefinedGlobal(results, callback) end end +local function searchUnusedLabel(results, callback) + for _, label in ipairs(results.labels) do + for _, info in ipairs(label) do + if info.type == 'goto' then + goto NEXT_LABEL + end + end + for _, info in ipairs(label) do + if info.type == 'set' then + callback(info.source.start, info.source.finish, label.key) + end + end + ::NEXT_LABEL:: + end +end + return function (ast, results, lines) local datas = {} -- 搜索未使用的局部变量 @@ -75,5 +91,15 @@ return function (ast, results, lines) message = 'Undefined global', -- LOCALE } end) + -- 搜索未使用的Label + searchUnusedLabel(results, function (start, finish, code) + datas[#datas+1] = { + start = start, + finish = finish, + level = 'Warning', + code = code, + message = 'Unused label', -- LOCALE + } + end) return datas end |