diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-06 14:04:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-06 14:04:48 +0800 |
commit | 10a3015579f7104b7c6306ffae40361ba96c202f (patch) | |
tree | 14ce25ab99f5a0f3bd01dc8fdaa5ae0504c18002 /server/src | |
parent | 91b0bd8f72687f94342f384a916638fc87f1fabb (diff) | |
download | lua-language-server-10a3015579f7104b7c6306ffae40361ba96c202f.zip |
未使用的Label
Diffstat (limited to 'server/src')
-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 |