haskell / haskell-language-server

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

Inlay hints for deriving strategies #4213

Open michaelpj opened 2 months ago

michaelpj commented 2 months ago

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

When you use deriving without deriving strategies, the choice of how the instance is derived is implicit. We could make this explicit with inlay hints.

Describe the solution you'd like

data Foo ...
  deriving <hint>stock</hint> (Eq, Ord)

The tricky bit will be if we have a list of derived classes which use different strategies! I would suggest something like:

data Foo ...
   deriving <hint>stock,anyclass</hint> (Eq, ToJSON)

Triggering this would of course produce

data Foo ..
   deriving stock Eq
   deriving anyclass ToJSON
michaelpj commented 2 months ago

This would be useful as a code action also, so we should make sure to expose it as a code action handler too. "Make deriving strategies explicit" or something.

michaelpj commented 4 days ago

On reflection I think this might actually be quite hard: knowing which deriving strategy GHC has chosen is not easy, I think. There has been some work in GHC to expose this information in the diagnostics, we might need to wait for that: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12817

michaelpj commented 4 days ago

We could maybe take some the code from that PR, but it's fairly non-trivial!