diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-06 14:45:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-06 14:45:53 +0800 |
commit | e228f090618a68a96fee30c40b9d7d10e04ed12d (patch) | |
tree | b6705582f32b0fb633c03b7ba786383ae3b176c2 /server/src/matcher | |
parent | 4db5bdc9c062df4bbbeaec55f09ab6902bdf731a (diff) | |
download | lua-language-server-e228f090618a68a96fee30c40b9d7d10e04ed12d.zip |
检查空行
Diffstat (limited to 'server/src/matcher')
-rw-r--r-- | server/src/matcher/diagnostics.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua index d347d9ab..e5daea31 100644 --- a/server/src/matcher/diagnostics.lua +++ b/server/src/matcher/diagnostics.lua @@ -72,6 +72,26 @@ local function searchUnusedLabel(results, callback) end end +local function serachSpaces(lines, callback) + for i = 1, #lines do + local line = lines:line(i) + + if line:find '^[ \t]+$' then + local start, finish = lines:range(i) + callback(start, finish, 'Line with spaces only') -- LOCALE + goto NEXT_LINE + end + + local pos = line:find '[ \t]+$' + if pos then + local start, finish = lines:range(i) + callback(start + pos - 1, finish, 'Line with postspace') -- LOCALE + goto NEXT_LINE + end + ::NEXT_LINE:: + end +end + return function (ast, results, lines) local datas = {} -- 搜索未使用的局部变量 @@ -104,5 +124,14 @@ return function (ast, results, lines) message = 'Unused label', -- LOCALE } end) + -- 所搜只有空格与制表符的行,以及后置了空格的行 + serachSpaces(lines, function (start, finish, message) + datas[#datas+1] = { + start = start, + finish = finish, + level = 'Warning', + message = message, + } + end) return datas end |