haskell / haskell/haskell-language-server

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

Open
#2,922 2 comments 1 reaction 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
3d 21h
Merged PRs (30d)
13

Description

**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:
```haskell
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

Contributor guide

No contributing guide indexed for this repository

Research direction

No files, tests, or entry points are named. Start by locating the go-to-definition implementation and the existing type-class resolution behavior, then review related issue #2478. Done means concrete, compile-time-known instances open at their method definitions while ambiguous contexts retain current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.