diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-21 18:44:10 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-21 18:44:10 +0800 |
commit | 25bea6bab76ab45549aeb9a9dc28f34536b663c5 (patch) | |
tree | 0d62d4e5c658f6ed486979055922620153a8fb10 /server/src | |
parent | 3b17bd6cb09034b74405301c53782cee6e91a2f2 (diff) | |
download | lua-language-server-25bea6bab76ab45549aeb9a9dc28f34536b663c5.zip |
不检查字符串内部的前置与后置空格
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/matcher/diagnostics.lua | 29 |
1 files changed, 26 insertions, 3 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, |