LuaLS / LuaLS/lua-language-server
Diagnostics for incorrect use of ipairs
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
An enhancement idea: I ran into a subtle bug in my own code where I used `ipairs` instead of `pairs`. Would it be possible for the Lua language server to warn about such usage? This is assuming it knows the type being iterated (or maybe if it's explicitly annotated). For example:
```lua
---@type table
local x = { a = 1, b = 2 }
for k, v in ipairs(x) do -- most likely a mistake
print(k, v)
end
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files or tests are named. Start by locating LuaLS diagnostics for ipairs and the type analysis for annotated tables, then trace how the example's table type is represented. Done means the example can produce a warning when ipairs is used for the annotated key-value table, with the intended diagnostic behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100