haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 367 forks source link

`textDocument/references` on a record field in a definition returns way too many things with ghc 9.6.4 #4412

Open googleson78 opened 1 month ago

googleson78 commented 1 month ago

This is essentially a duplicate of #3731, because I am now running 9.6.4, and it is still not fixed. I've copied over the original text below.


Is your enhancement request related to a problem? Please describe.

Currently, calling textDocument/references on the field of a record in a definition returns way too many things, including all of the other record fields, as well as the data type definition line, as well as some seemingly duplicate entries. Example:

For this file

{-# LANGUAGE RecordWildCards #-}
data Foo = MkFoo
  {
    bar :: Int,
    baz :: String
  }

fooUse0 :: Foo -> Int
fooUse0 MkFoo{bar} = 5

fooUse1 :: Foo -> Int
fooUse1 MkFoo{..} = 6

fooUse2 :: Int -> String -> Foo
fooUse2 bar baz =
  MkFoo{..}

Calling textDocument/references while my cursor is on bar on line 4 returns the following results: 2023-07-26-165942_636x284_scrot A lot of these seem redundant:

  1. The constructor definition (the last result)
  2. Some of the lines are seemingly duplicated - fooUse1 and fooUse2 are both seemingly mentioned twice, which seems like a bug?
  3. (my biggest issue) baz :: String also comes up as a result, which also seems like a bug, and is a huge pain when dealing with Real World :tm: data types with loads of fields, as this happens for each field.

Describe the solution you'd like

I would like for only lines that mention the field in question to show up.

Describe alternatives you've considered

Maybe I'm just confused regarding what "references" means?

soulomoon commented 4 weeks ago

Related to #2915 Internally they should be the same issue, we reference record field to an incorrect code range.

we have a potential fix #4089 by @jhrcek