wz1000 / HieDb

Generates a references DB from .hie files
BSD 3-Clause "New" or "Revised" License
64 stars 24 forks source link

Record constructors being given as references to the fields with GHC versions >= 9 #45

Open OliverMadine opened 2 years ago

OliverMadine commented 2 years ago

Example

newtype Foo = Foo { field :: Int }

When querying for the point-refs at line 1 column 22 (i.e. on the field name), the Foo constructor is given as a reference.

Version

This seems to only be an issue with GHC versions >= 9

This is causing haskell-language-server/#2915.

michaelpj commented 2 years ago

Nag @wz1000 ?

deemp commented 1 year ago

Hi, @wz1000! Any news on that?

jhrcek commented 8 months ago

I looked into where these duplicate references to data constructors are coming from and here's what I found:

For this example module

module A where
data Foo = Bar { a :: !Int , b :: !Int }

We end up with the following in the refmap here

 (Right Bar,
  [ (A.hs:2:12-14, Details:  Nothing {declaration of constructor bound at: A.hs:2:12-40})
  , (A.hs:2:18, Details:  Nothing {usage}) -- corresponds to src span of "a" field
  , (A.hs:2:30, Details:  Nothing {usage}) -- corresponds to src span of "b" field
  ])

This flat function "flattens" this info into

[ (Right Bar, (A.hs:2:12-14, Details:  Nothing {declaration of constructor bound at: A.hs:2:12-40}))
, (Right Bar, (A.hs:2:18, Details:  Nothing {usage}))
, (Right Bar, (A.hs:2:30, Details:  Nothing {usage}))
]

and we end up with 3 references to Bar constructor, although just one of the 3 identifierDetails in the RefMap was actual reference to the Bar constructor:

image

@wz1000 I could use some hints on how to proceed. Is it a) a bug in how ghc generates a ref map, including IdentifierDetails under Bar constructors that shouldn't be there? b) a bug in indexing code - which should filter out the constructor fields and only index actual reference to the Bar constructor?