lua-language-server
lua-language-server copied to clipboard
Unexpected `textDocument/references` results on keys inside nested tables
Describe the bug
textDocument/references is returning unexpected results when used in a specific situation (more about that below).
To Reproduce
- Paste the following snippet in a lua file
ENUM = {
VALUE1 = 1,
VALUE2 = 2,
}
a = {
{ type = ENUM.VALUE1 },
{ type = ENUM.VALUE1 },
{ type = ENUM.VALUE2 },
}
- Move cursor over the 1st instance of
"type"key in theatable - Request references (
textDocument/references) - 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
These 3 "type" keys are not semantically related, so I search for references by their values.
Maybe the values make sense on paper but in practice keys are a lot more tied together
Maybe the values make sense on paper but in practice keys are a lot more tied together
Unless I do something special for this situation, it won't be able to achieve what you want.
I'll leave such judgment up to you, at least have the set of elements in references and rename match.
I agree with @RaafatTurki that this seems like incorrect behavior. type and ENUM.VALUE are unrelated instances.
The same problem can be observed using this example:
local print = print
When requesting references for the local print, there should only be one reference, not two.