LuaLS / LuaLS/lua-language-server

Diagnostics for incorrect use of ipairs

Open
#1,917 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.