-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Display instances on hover for type and data constructors #3963
base: master
Are you sure you want to change the base?
Conversation
7adc0ac
to
eb7c90b
Compare
It looks cool, 🤔 how is the result sorted, should we sort the result? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look good, some questions
@@ -59,6 +60,7 @@ import Data.List.Extra (dropEnd1, nubOrd) | |||
|
|||
import Data.Version (showVersion) | |||
import Development.IDE.Types.Shake (WithHieDb) | |||
import GHC (getInstancesForType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get it from Compat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since in general we import ghc stuff from Development.IDE.GHC.Compat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I should just export it in Development.IDE.GHC.Compat
? Why is this needed? It seems to be available in this module in all the ghc versions supported by hls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure of our policy here, wdyt @wz1000 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks plausible to me, I'd like a review from @wz1000 . And it needs some tests.
I note that we have a problem in our hovers in that there are no explanations for what the various sections of the hover mean. In this case I think it's obvious, but perhaps we could take the opportunity to add titles to the sections? For this bit I think it could just be Instances in scope for <name>
?
where | ||
instancesForName :: IO (Maybe [ClsInst]) | ||
instancesForName = runMaybeT $ do | ||
typ <- MaybeT . pure $ lookupNameEnv km n >>= tyThingToType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we look things up repeatedly in km
. Should we do this once and then just pass in the TyThing
to all the places that need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean. I think the lookup only happens once per Name
and we need to look it up for each Name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean in the other functions we call around here. Probably not a huge deal
@@ -308,6 +311,24 @@ atPoint IdeOptions{} (HAR _ hf _ _ (kind :: HieKind hietype)) (DKMap dm km) env | |||
UnhelpfulLoc {} | isInternalName name || isSystemName name -> Nothing | |||
_ -> Just $ "*Defined " <> printOutputable (pprNameDefnLoc name) <> "*" | |||
|
|||
prettyInstances :: (Either ModuleName Name, IdentifierDetails hietype) -> IO (Maybe T.Text) | |||
prettyInstances (Right n, _) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cases like this I'd usually just make the function take what it needs (just a Name
) and get the caller to worry about massaging the list into the right form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds better, I switched it up
@@ -59,6 +60,7 @@ import Data.List.Extra (dropEnd1, nubOrd) | |||
|
|||
import Data.Version (showVersion) | |||
import Development.IDE.Types.Shake (WithHieDb) | |||
import GHC (getInstancesForType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure of our policy here, wdyt @wz1000 ?
eb7c90b
to
e80d081
Compare
About the titles, I personally don't think it is too useful, imo it would just add unecessary clutter in the hover text. |
hum, I used it a bit more and there are a few issues with this feature as it is currently implemented actually. |
Yes fine, we can leave the title thing for later |
I looked a bit into it and I might need some guidance, there are some things I don't really understand. I believe the issue comes from there clsInst <- liftIO $ evalGhcEnv env $ getInstancesForType typ It seems that the Doesn't the I found this function in the I am guessing there are some things like types and docstrings that are cheap to reload but instances is not part of these. |
39a6e25
to
cf69ce5
Compare
Perhaps we are not taking care of things that is not used yet, you can dig deeper to see how do we manage to include the information in the session. |
An attempt to implement the requested enhancement in #3098
It displays the list of typeclass instances a type has when requesting hover information.
It should work on type constructors as well as the data constructors, using the related type.
It is added as a new section at the end of the hover information.
Here is an example of how it looks when hovering on

Maybe
orJust
orNothing
It seems to also be scope aware, if I import new instances then they will be added to the list. For example if I install

hashable
andimport Data.Hashable
with theHashable
instance forInt
and hover onInt
I get an additionalwhich is pretty cool.