-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing implicit parameter #105
Labels
Comments
Thanks for reporting! I agree that it would be useful indeed, but not sure how difficult it will be. If anyone wants to take a shot at this, we can try to help out. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
When working in a codebase with lots of implicits, e.g. using the tagless final technique, you find yourself adding implicit parameters or context bounds quite often when trying to use an interface you haven't used before.
Currently, when you make a call to such an interface, Metals will happily help you with an import on completion / in the quick fix, but you'll only have the type, not the value. The type needs to be added manually to the implicit parameter list (if there is one in the surrounding definitions) or the context bounds (if the missing implicit contains any of the type parameters of the surrounding definitions).
Describe the solution you'd like
A quick fix available on positions with missing implicits.
Let's have an example:
This complies fine. Let's replace the placeholder with some references to some implicits:
Now we get errors in two positions: at
Alg[F]
(missing implicit) andempty[A]
(missing implicit):If we add the necessary constraints, we'll also get an error due to the missing implicit
Execution
.Some of the ways an inspection could help:
Quick fix on
Alg[F]
:Alg[F]
parameter toExample
's primary constructorAlg[F]
to a new implicit parameter list ininstance
(adding to an existing list if present)Quick fix on
empty[A]
:Monoid[A]
parameter ininstance
Ideally, the specifics on where to insert the parameter would be some sort of context menu separate from the short list of quick fixes (much like creating new Scala files in vscode), so that it's not polluted with too many options at once. Ideally, with a preview, but I underestand that might be much harder to implement.
Describe alternatives you've considered
Manually adding required parameters to the desired location.
Additional context
Some implicits might be harder to define as context bounds, for example
MonadError[*[_], Throwable]
(using kind-projector syntax). For these, we could start by only adding them as normal implicit parameters.Search terms:
Context bounds, type class constraints, effect polymorphic, cats-effect
The text was updated successfully, but these errors were encountered: