LuaLS / LuaLS/lua-language-server

Unexpected `textDocument/references` results on keys inside nested tables

Open
#1,281 5 comments 1 reaction 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

**Describe the bug**
`textDocument/references` is returning unexpected results when used in a specific situation (more about that below).

**To Reproduce**
1. Paste the following snippet in a lua file
```lua
ENUM = {
VALUE1 = 1,
VALUE2 = 2,
}

a = {
{ type = ENUM.VALUE1 },
{ type = ENUM.VALUE1 },
{ type = ENUM.VALUE2 },
}
```
2. Move cursor over the 1st instance of `"type"` key in the `a` table
3. Request references (`textDocument/references`)
4. Observe the faulty results which comprise of the hovered `"type"` key + both instances of `"VALUE1"`

**Expected behavior**
Results that comprise of all 3 instances of `"type"` key

**Additional context**
`textDocument/rename` on the other hand only renames the hovered `"type"` key while expected to rename all 3 of its instances

**Environment**
- OS: Linux
- Client: Neovim

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

Reproduce the issue in a Lua file using the shown nested-table example and request textDocument/references on the first type key. Compare the returned locations with textDocument/rename behavior; done means references include all three type keys without including VALUE1 or VALUE2.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.