summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/diagnostics.lua29
-rw-r--r--server/test/diagnostics/init.lua12
2 files changed, 32 insertions, 9 deletions
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua
index f4160f13..7871bdca 100644
--- a/server/src/matcher/diagnostics.lua
+++ b/server/src/matcher/diagnostics.lua
@@ -70,12 +70,31 @@ local function searchUnusedLabel(results, callback)
end
end
-local function serachSpaces(lines, callback)
+local function isContainPos(obj, start, finish)
+ if obj.start <= start and obj.finish + 1 >= finish then
+ return true
+ end
+ return false
+end
+
+local function isInString(vm, start, finish)
+ for _, source in ipairs(vm.results.strings) do
+ if isContainPos(source, start, finish) then
+ return true
+ end
+ end
+ return false
+end
+
+local function searchSpaces(vm, lines, callback)
for i = 1, #lines do
local line = lines:line(i)
if line:find '^[ \t]+$' then
local start, finish = lines:range(i)
+ if isInString(vm, start, finish) then
+ goto NEXT_LINE
+ end
callback(start, finish, 'Line with spaces only') -- LOCALE
goto NEXT_LINE
end
@@ -83,7 +102,11 @@ local function serachSpaces(lines, callback)
local pos = line:find '[ \t]+$'
if pos then
local start, finish = lines:range(i)
- callback(start + pos - 1, finish, 'Line with postspace') -- LOCALE
+ start = start + pos - 1
+ if isInString(vm, start, finish) then
+ goto NEXT_LINE
+ end
+ callback(start, finish, 'Line with postspace') -- LOCALE
goto NEXT_LINE
end
::NEXT_LINE::
@@ -198,7 +221,7 @@ return function (vm, lines, uri)
}
end)
-- 只有空格与制表符的行,以及后置空格
- serachSpaces(lines, function (start, finish, message)
+ searchSpaces(vm, lines, function (start, finish, message)
datas[#datas+1] = {
start = start,
finish = finish,
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index 4fb15448..fc425e6b 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -147,9 +147,9 @@ TEST [[
(''):sub(1, 2)
]]
--- TODO
---TEST [=[
---return [[
---
---]]
---]=]
+
+TEST [=[
+return [[
+
+]]
+]=]