diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-16 11:27:17 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-16 11:27:17 +0800 |
commit | 8c464f8fa237d85d2c99c7b36d8a62d9bcecda81 (patch) | |
tree | 85c6d6bdcd9ab446cd924bad745da5c05bdec070 /script-beta/core | |
parent | 4e23000383857307e33ec255fe71e2e020413615 (diff) | |
download | lua-language-server-8c464f8fa237d85d2c99c7b36d8a62d9bcecda81.zip |
诊断检查 break 后的代码
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/diagnostics/code-after-break.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/script-beta/core/diagnostics/code-after-break.lua b/script-beta/core/diagnostics/code-after-break.lua new file mode 100644 index 00000000..a2bac8a4 --- /dev/null +++ b/script-beta/core/diagnostics/code-after-break.lua @@ -0,0 +1,34 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local define = require 'proto.define' + +return function (uri, callback) + local state = files.getAst(uri) + if not state then + return + end + + local mark = {} + guide.eachSourceType(state.ast, 'break', function (source) + local list = source.parent + if mark[list] then + return + end + mark[list] = true + for i = #list, 1, -1 do + local src = list[i] + if src == source then + if i == #list then + return + end + callback { + start = list[i+1].start, + finish = list[#list].range or list[#list].finish, + tags = { define.DiagnosticTag.Unnecessary }, + message = lang.script.DIAG_CODE_AFTER_BREAK, + } + end + end + end) +end |