Description
Is your feature request related to a problem? Please describe.
The overall goal is to find packages where orphan instances are defined and include them automatically into the project.
For example, using the cereal package and deriving an instance for a record with a field of type Text
:
data Request
= Req { msg :: Text }
deriving (Generic, Serialize)
ghc will give us an error message like this:
• No instance for (Serialize Text)
arising from the 'deriving' clause of a data type declaration
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
• When deriving the instance for (Serialize Request)
|
18 | deriving (Generic, Serialize)
| ^^^^^^^^^
Searching for the error message does not get you very far, hoogle (at this moment) does not give you an answer either. So you have to navigate through Hackage in the right way to find a package which defines the instance (in this case that's cereal-text), alter the cabal/stack file to get the dependency and import the correct module.
Describe the solution you'd like
Ideally, HLS goes on to search for the orphan instance, if it finds a suitable one it provides a code-action to add the package to the project and add the import statement to the module.
Describe alternatives you've considered
The biggest problem here seems to be the lookup from (TypeClass, DataType) -> package
. We need to explore if we can fetch this information somehow somewhere first. These options are currently on the table:
- Hoogle,
- hackage-index,
- searching through hackage somehow.
For (1) and (2) we are not sure if the data is in the given database at all nor if it's possible to query the data. I talked to an HLS contributor suggesting (3) without really knowing how.
Additional context
@benjaminweb, @dispanser and me came up with this idea on ZuriHac 2022. @fendor gave some first advices.