Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Show where instances are defined #748

Merged
merged 4 commits into from
Mar 21, 2018

Conversation

harpocrates
Copy link
Collaborator

This is analogous to what GHCi's :info command does - it displays in the instance details where the instance was defined.

ghci> :info Bool
data Bool = False | True        -- Defined in ‘GHC.Types’
instance Bounded Bool -- Defined in ‘GHC.Enum’
instance Enum Bool -- Defined in ‘GHC.Enum’
instance Eq Bool -- Defined in ‘GHC.Classes’
instance Ord Bool -- Defined in ‘GHC.Classes’
instance Read Bool -- Defined in ‘GHC.Read’
instance Show Bool -- Defined in ‘GHC.Show’
instance Ix Bool -- Defined in ‘GHC.Arr’

Here is a snippet of the instances for Bool (Note the "(Defined in ...)" links):

screen shot 2018-02-08 at 6 23 56 pm

This fixes #296 as much as it can ever really hope to be fixed.

@harpocrates
Copy link
Collaborator Author

Woops! I had forgotten about data and type families (I've never been bitten by this, but I can imagine it would be annoying to have a type family be stuck just because you forgot to import the right module...). Here is what that looks like:

screen shot 2018-02-08 at 7 00 16 pm

Copy link
Member

@alexbiehl alexbiehl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really useful! Thanks Alec.

@@ -388,7 +388,7 @@ mkPseudoFamilyDecl (FamilyDecl { .. }) = PseudoFamilyDecl


-- | An instance head that may have documentation and a source location.
type DocInstance name = (InstHead name, Maybe (MDoc (IdP name)), Located (IdP name))
type DocInstance name = (InstHead name, Maybe (MDoc (IdP name)), Located (IdP name), Maybe Module)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this is a breaking change :( This has to go into the next major version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspected as much... Should I reopen this PR on ghc-head then?

where
pdata = keyword "data" <+> typ
pdecl = pdata <+> ppShortDataDecl False True dd [] unicode qual
where
mname = maybe noHtml (\m -> hsep [toHtml "(Defined in", ppModule m, toHtml ")"]) mdl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave out the parenthesis, they look bad and are completely unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@alexbiehl alexbiehl mentioned this pull request Feb 11, 2018
2 tasks
@alexbiehl alexbiehl force-pushed the feature/show-instance-mod branch 2 times, most recently from a727a19 to f6b36d5 Compare March 2, 2018 17:30
Above instance, we now also display a link to the module where the
instance was defined. This is sometimes helpful in figuring out
what to import.
@harpocrates harpocrates force-pushed the feature/show-instance-mod branch from f6b36d5 to 0352997 Compare March 19, 2018 18:30
@harpocrates
Copy link
Collaborator Author

@alexbiehl Gentle ping on this. If you are waiting to merge this after #721, that's fine - I just want to make sure this isn't forgotten. Once this gets merged, I'll also fix the tests on #749.

@alexbiehl
Copy link
Member

Alec, sorry. I didn't notice you pushed an update to this one. Merging right away.

@alexbiehl alexbiehl merged commit b7a74c6 into haskell:ghc-8.4 Mar 21, 2018
alexbiehl pushed a commit that referenced this pull request Mar 27, 2018
* Indicate source module of instances

Above instance, we now also display a link to the module where the
instance was defined. This is sometimes helpful in figuring out
what to import.

* Source module for type/data families too

* Remove parens

* Accept tests
sjakobi pushed a commit to sjakobi/haddock that referenced this pull request Jun 10, 2018
* Indicate source module of instances

Above instance, we now also display a link to the module where the
instance was defined. This is sometimes helpful in figuring out
what to import.

* Source module for type/data families too

* Remove parens

* Accept tests

(cherry picked from commit b7a74c6)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants