Skip to content

Commit

Permalink
fix #1365
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jul 25, 2022
1 parent 3783510 commit 2673232
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* `FIX` [#1354](https://github.com/sumneko/lua-language-server/issues/1354)
* `FIX` [#1355](https://github.com/sumneko/lua-language-server/issues/1355)
* `FIX` [#1363](https://github.com/sumneko/lua-language-server/issues/1363)
* `FIX` [#1365](https://github.com/sumneko/lua-language-server/issues/1365)
* `FIX` [#1368](https://github.com/sumneko/lua-language-server/issues/1368)

## 3.5.0
Expand Down
13 changes: 8 additions & 5 deletions script/core/diagnostics/count-down-loop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ return function (uri, callback)
end

guide.eachSourceType(state.ast, 'loop', function (source)
local maxNumer = source.max and tonumber(source.max[1])
if maxNumer ~= 1 then
local maxNumber = source.max and tonumber(source.max[1])
if not maxNumber then
return
end
local minNumber = source.init and tonumber(source.init[1])
if minNumber and minNumber <= 1 then
if minNumber and maxNumber and minNumber <= maxNumber then
return
end
if not minNumber and maxNumber > 1 then
return
end
if not source.step then
Expand All @@ -24,7 +27,7 @@ return function (uri, callback)
finish = source.max.finish,
message = lang.script('DIAG_COUNT_DOWN_LOOP'
, ('%s, %s'):format(text:sub(
guide.positionToOffset(state, source.init.start),
guide.positionToOffset(state, source.init.start + 1),
guide.positionToOffset(state, source.max.finish)
), '-1')
)
Expand All @@ -37,7 +40,7 @@ return function (uri, callback)
finish = source.step.finish,
message = lang.script('DIAG_COUNT_DOWN_LOOP'
, ('%s, -%s'):format(text:sub(
guide.positionToOffset(state, source.init.start),
guide.positionToOffset(state, source.init.start + 1),
guide.positionToOffset(state, source.max.finish)
), source.step[1])
)
Expand Down
12 changes: 12 additions & 0 deletions test/diagnostics/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,18 @@ for i = <!10, 1, 5!> do
end
]]

TEST [[
for i = <!100, 10, 1!> do
print(i)
end
]]

TEST [[
for i = <!1, -10!> do
print(i)
end
]]

TEST [[
for i = 1, 1 do
print(i)
Expand Down

0 comments on commit 2673232

Please sign in to comment.