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

Display the derived instances while hovering on type constructors and data constructors

Open July541 opened this issue 3 years ago • 7 comments

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

No

Describe the solution you'd like

Display the derived instances while hovering on type constructors and data constructors.

For example, for data A = A deriving Show; a = A, it would be great to display it derived the Show while hovering over all As

Describe alternatives you've considered

Not sure if there is a better way to show these instances

Additional context

July541 avatar Aug 12 '22 15:08 July541

Is there a reason for only derived instances rather than all instances, like :instances in GHCi?

ghci> :instances Int
instance Foreign.Storable.Storable Int
  -- Defined in `Foreign.Storable'
instance GHC.Bits.Bits Int -- Defined in `GHC.Bits'
instance GHC.Bits.FiniteBits Int -- Defined in `GHC.Bits'
instance Integral Int -- Defined in `GHC.Real'
instance GHC.Ix.Ix Int -- Defined in `GHC.Ix'
instance Num Int -- Defined in `GHC.Num'
instance Real Int -- Defined in `GHC.Real'
instance Bounded Int -- Defined in `GHC.Enum'
instance Enum Int -- Defined in `GHC.Enum'
instance Eq Int -- Defined in `GHC.Classes'
instance Ord Int -- Defined in `GHC.Classes'
instance Read Int -- Defined in `GHC.Read'
instance Show Int -- Defined in `GHC.Show'

Also, class constraints on local type variables?

Jashweii avatar Aug 13 '22 03:08 Jashweii

Is there a reason for only derived instances rather than all instances, like :instances in GHCi?

When I said derived, it also includes these instances you mentioned.

Also, class constraints on local type variables?

Not sure about that, an example here?

July541 avatar Aug 14 '22 12:08 July541

Also, class constraints on local type variables?

Not sure about that, an example here?

Like a in these examples though I guess it isn't necessarily restricted to type variables

eg1 :: forall a . Show a => a -> String
eg1 = show @a

data Eg2 a where
  MkEg2 :: Show a => Eg2 a
eg2 :: forall a . Eg2 a -> a -> String
eg2 MkEg2 = show @a

Jashweii avatar Aug 14 '22 12:08 Jashweii

It has a lower priority in this thread I think, because of these variables are not far from the class name.

July541 avatar Aug 15 '22 14:08 July541

Showing all the instances might be a lot. Some types have a lot of instances. But perhaps that's fine, so long as it goes at the bottom or something, like in Haddock.

michaelpj avatar Aug 16 '22 09:08 michaelpj

I took a look yesterday but didn't find an entrance about deriving info from typechecked source, glad to hear some hints.

July541 avatar Aug 16 '22 14:08 July541

I took a look yesterday but didn't find an entrance about deriving info from typechecked source, glad to hear some hints.

This might help, GHCi has a :instances <type> command https://gitlab.haskell.org/ghc/ghc/-/merge_requests/720 https://downloads.haskell.org/ghc/9.0.1/docs/html/libraries/ghc-9.0.1/GHC-Runtime-Eval.html#v:getInstancesForType

Jashweii avatar Aug 16 '22 17:08 Jashweii