lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

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

Open RaafatTurki opened this issue 3 years ago • 5 comments

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
ENUM = {
  VALUE1 = 1,
  VALUE2 = 2,
}

a = {
  { type = ENUM.VALUE1 },
  { type = ENUM.VALUE1 },
  { type = ENUM.VALUE2 },
}
  1. Move cursor over the 1st instance of "type" key in the a table
  2. Request references (textDocument/references)
  3. 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

RaafatTurki avatar Jul 05 '22 02:07 RaafatTurki

These 3 "type" keys are not semantically related, so I search for references by their values.

sumneko avatar Jul 05 '22 08:07 sumneko

Maybe the values make sense on paper but in practice keys are a lot more tied together

RaafatTurki avatar Jul 05 '22 15:07 RaafatTurki

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.

sumneko avatar Jul 06 '22 08:07 sumneko

I'll leave such judgment up to you, at least have the set of elements in references and rename match.

RaafatTurki avatar Jul 06 '22 08:07 RaafatTurki

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.

smjonas avatar Jul 17 '22 07:07 smjonas