diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-10 20:58:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-10 20:58:05 +0800 |
commit | 39de6077b1a1a6224d1acb52d17ab8ba7c885305 (patch) | |
tree | 7867c694b4877b4ba2889e125d99102314b4ffd5 | |
parent | d12f4c82488685770dda1ab8d4f361e2662dd31f (diff) | |
download | lua-language-server-39de6077b1a1a6224d1acb52d17ab8ba7c885305.zip |
更新行尾空白诊断实现
-rw-r--r-- | server-beta/src/core/diagnostics/trailing-space.lua | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/server-beta/src/core/diagnostics/trailing-space.lua b/server-beta/src/core/diagnostics/trailing-space.lua index ef7fbef1..e54a6e60 100644 --- a/server-beta/src/core/diagnostics/trailing-space.lua +++ b/server-beta/src/core/diagnostics/trailing-space.lua @@ -17,41 +17,39 @@ return function (uri, callback) if not ast then return end - local lines = files.getLines(uri) local text = files.getText(uri) - + local lines = files.getLines(uri) for i = 1, #lines do - local start = lines[i].start + 1 - local finish = lines[i].finish - 1 - local line = text:sub(start, finish) - if line:find '^[ \t]+[\r\n]*$' then - local offset = guide.offsetOf(lines, i-1, start-1) - if isInString(ast.ast, offset) then - goto NEXT_LINE + local start = lines[i].start + local range = lines[i].range + local lastChar = text:sub(range, range) + if lastChar ~= ' ' and lastChar ~= '\t' then + goto NEXT_LINE + end + if isInString(ast.ast, range) then + goto NEXT_LINE + end + local first = start + for n = range - 1, start, -1 do + local char = text:sub(n, n) + if char ~= ' ' and char ~= '\t' then + first = n + 1 + break end + end + if first == start then callback { - start = start, - finish = finish, + start = first, + finish = range, message = lang.script.DIAG_LINE_ONLY_SPACE, } - goto NEXT_LINE - end - - local pos = line:find '[ \t]+[\r\n]*$' - if pos then - start = start + pos - 1 - local offset = guide.offsetOf(lines, i-1, start-1) - if isInString(ast.ast, offset) then - goto NEXT_LINE - end + else callback { - start = start, - finish = finish, + start = first, + finish = range, message = lang.script.DIAG_LINE_POST_SPACE, } - goto NEXT_LINE end - ::NEXT_LINE:: end end |