summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/trailing-space.lua
diff options
context:
space:
mode:
authorArcanox <arcanox@arcanox.me>2021-09-25 18:00:15 -0500
committerArcanox <arcanox@arcanox.me>2021-09-25 18:00:15 -0500
commitdc685d1addad2f2e57f55a20bb6cca79c222c130 (patch)
treeabb200fd7f217460a4543cb6f32af7ebac308bc0 /script/core/diagnostics/trailing-space.lua
parenta465b35d5eefc11c1daf3c29b41ce95ee098a782 (diff)
parent1f0a2d0e9283a4cb7f7b3fc72258eb1c5ba4e5dd (diff)
downloadlua-language-server-dc685d1addad2f2e57f55a20bb6cca79c222c130.zip
Merge branch 'master' into improve-semantic-highlighting
# Conflicts: # script/core/semantic-tokens.lua
Diffstat (limited to 'script/core/diagnostics/trailing-space.lua')
-rw-r--r--script/core/diagnostics/trailing-space.lua35
1 files changed, 19 insertions, 16 deletions
diff --git a/script/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua
index 824eb83f..cc51cf77 100644
--- a/script/core/diagnostics/trailing-space.lua
+++ b/script/core/diagnostics/trailing-space.lua
@@ -13,40 +13,43 @@ local function isInString(ast, offset)
end
return function (uri, callback)
- local ast = files.getState(uri)
- if not ast then
+ local state = files.getState(uri)
+ if not state then
return
end
local text = files.getText(uri)
- local lines = files.getLines(uri)
- for i = 1, #lines do
- local start = lines[i].start
- local range = lines[i].range
- local lastChar = text:sub(range, range)
+ local lines = state.lines
+ for i = 0, #lines do
+ local startOffset = lines[i]
+ local finishOffset = text:find('[\r\n]', startOffset) or (#text + 1)
+ local lastOffset = finishOffset - 1
+ local lastChar = text:sub(lastOffset, lastOffset)
if lastChar ~= ' ' and lastChar ~= '\t' then
goto NEXT_LINE
end
- if isInString(ast.ast, range) then
+ local lastPos = guide.offsetToPosition(state, lastOffset)
+ if isInString(state.ast, lastPos) then
goto NEXT_LINE
end
- local first = start
- for n = range - 1, start, -1 do
+ local firstOffset = startOffset
+ for n = lastOffset - 1, startOffset, -1 do
local char = text:sub(n, n)
if char ~= ' ' and char ~= '\t' then
- first = n + 1
+ firstOffset = n + 1
break
end
end
- if first == start then
+ local firstPos = guide.offsetToPosition(state, firstOffset) - 1
+ if firstOffset == startOffset then
callback {
- start = first,
- finish = range,
+ start = firstPos,
+ finish = lastPos,
message = lang.script.DIAG_LINE_ONLY_SPACE,
}
else
callback {
- start = first,
- finish = range,
+ start = firstPos,
+ finish = lastPos,
message = lang.script.DIAG_LINE_POST_SPACE,
}
end