haskell / haskell-language-server

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

Go to definition of the instance of a method instead of its type definition in type class #2922

Open anka-213 opened 2 years ago

anka-213 commented 2 years ago

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

When code uses a lot of type classes, it would be useful to go to the definition of the actual method that will be called in the concrete instance instead of the abstract declaration in the class.

For example, when using Data.Binary, code often looks like this:

instance Binary Foo where
  get = Foo <$> get <*> get

in this case, go to definition is not very useful, since it only takes you to the Binary class itself instead of something concrete.

Describe the solution you'd like

If the concrete instance that will be used is known at compile time (i.e. when there is no SomeTypeClass a => context on the current function), go to definition should take you to the instance's method instead of the class. Otherwise, the current behaviour would be preserved.

Describe alternatives you've considered

An alternative would be to have this be some separate command, rather than the go-to-definition. I am not sure if this new behaviour would make it more difficult to go to the class declaration.

Additional context

Related to #2478

michaelpj commented 2 years ago

I wonder if this would be fixed by https://github.com/haskell/haskell-language-server/pull/1983 ?

anka-213 commented 2 years ago

Yes, that sounds like exactly what I was looking for!