Skip to content

Commit 2673232

Browse files
committed
fix #1365
1 parent 3783510 commit 2673232

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* `FIX` [#1354](https://github.com/sumneko/lua-language-server/issues/1354)
77
* `FIX` [#1355](https://github.com/sumneko/lua-language-server/issues/1355)
88
* `FIX` [#1363](https://github.com/sumneko/lua-language-server/issues/1363)
9+
* `FIX` [#1365](https://github.com/sumneko/lua-language-server/issues/1365)
910
* `FIX` [#1368](https://github.com/sumneko/lua-language-server/issues/1368)
1011

1112
## 3.5.0

script/core/diagnostics/count-down-loop.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ return function (uri, callback)
1010
end
1111

1212
guide.eachSourceType(state.ast, 'loop', function (source)
13-
local maxNumer = source.max and tonumber(source.max[1])
14-
if maxNumer ~= 1 then
13+
local maxNumber = source.max and tonumber(source.max[1])
14+
if not maxNumber then
1515
return
1616
end
1717
local minNumber = source.init and tonumber(source.init[1])
18-
if minNumber and minNumber <= 1 then
18+
if minNumber and maxNumber and minNumber <= maxNumber then
19+
return
20+
end
21+
if not minNumber and maxNumber > 1 then
1922
return
2023
end
2124
if not source.step then
@@ -24,7 +27,7 @@ return function (uri, callback)
2427
finish = source.max.finish,
2528
message = lang.script('DIAG_COUNT_DOWN_LOOP'
2629
, ('%s, %s'):format(text:sub(
27-
guide.positionToOffset(state, source.init.start),
30+
guide.positionToOffset(state, source.init.start + 1),
2831
guide.positionToOffset(state, source.max.finish)
2932
), '-1')
3033
)
@@ -37,7 +40,7 @@ return function (uri, callback)
3740
finish = source.step.finish,
3841
message = lang.script('DIAG_COUNT_DOWN_LOOP'
3942
, ('%s, -%s'):format(text:sub(
40-
guide.positionToOffset(state, source.init.start),
43+
guide.positionToOffset(state, source.init.start + 1),
4144
guide.positionToOffset(state, source.max.finish)
4245
), source.step[1])
4346
)

test/diagnostics/common.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,18 @@ for i = <!10, 1, 5!> do
10861086
end
10871087
]]
10881088

1089+
TEST [[
1090+
for i = <!100, 10, 1!> do
1091+
print(i)
1092+
end
1093+
]]
1094+
1095+
TEST [[
1096+
for i = <!1, -10!> do
1097+
print(i)
1098+
end
1099+
]]
1100+
10891101
TEST [[
10901102
for i = 1, 1 do
10911103
print(i)

0 commit comments

Comments
 (0)