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

Commit 133e9c2

Browse files
harpocratesalexbiehl
authored andcommitted
Preserve docs on type family instances (#867)
* Preserve docs on type family instances The only problem was that the instance location was slightly off for type family instances. * Accept output
1 parent c3eb3f0 commit 133e9c2

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

haddock-api/src/Haddock/Interface/Create.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,12 @@ mkMaps dflags pkgName gre instances decls = do
419419
instanceMap = M.fromList [ (getSrcSpan n, n) | n <- instances ]
420420

421421
names :: SrcSpan -> HsDecl GhcRn -> [Name]
422-
names l (InstD d) = maybeToList (M.lookup loc instanceMap) -- See note [2].
422+
names _ (InstD d) = maybeToList (M.lookup loc instanceMap) -- See note [2].
423423
where loc = case d of
424-
TyFamInstD _ -> l -- The CoAx's loc is the whole line, but only for TFs
424+
-- The CoAx's loc is the whole line, but only for TFs. The
425+
-- workaround is to dig into the family instance declaration and
426+
-- get the identifier with the right location.
427+
TyFamInstD (TyFamInstDecl d') -> getLoc (feqn_tycon (hsib_body d'))
425428
_ -> getInstLoc d
426429
names l (DerivD {}) = maybeToList (M.lookup l instanceMap) -- See note [2].
427430
names _ decl = getMainDeclBinder decl

haddock-api/src/Haddock/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Haddock.Types (
2828
import Control.Exception
2929
import Control.Arrow hiding ((<+>))
3030
import Control.DeepSeq
31+
import Control.Monad.IO.Class (MonadIO(..))
3132
import Data.Typeable
3233
import Data.Map (Map)
3334
import Data.Data (Data)
@@ -661,6 +662,8 @@ instance Monad ErrMsgGhc where
661662
m >>= k = WriterGhc $ runWriterGhc m >>= \ (a, msgs1) ->
662663
fmap (second (msgs1 ++)) (runWriterGhc (k a))
663664

665+
instance MonadIO ErrMsgGhc where
666+
liftIO m = WriterGhc (fmap (\x -> (x, [])) (liftIO m))
664667

665668
-----------------------------------------------------------------------------
666669
-- * Pass sensitive types

html-test/ref/TypeFamilies.html

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,10 @@
352352
> <a href="#" class="selflink"
353353
>#</a
354354
></td
355-
><td class="doc empty"
356-
></td
355+
><td class="doc"
356+
><p
357+
>External instance</p
358+
></td
357359
></tr
358360
><tr
359361
><td colspan="2"
@@ -586,8 +588,10 @@
586588
> <a href="#" class="selflink"
587589
>#</a
588590
></td
589-
><td class="doc empty"
590-
></td
591+
><td class="doc"
592+
><p
593+
>Doc for: type instance Foo X = Y</p
594+
></td
591595
></tr
592596
><tr
593597
><td colspan="2"
@@ -944,8 +948,10 @@
944948
> <a href="#" class="selflink"
945949
>#</a
946950
></td
947-
><td class="doc empty"
948-
></td
951+
><td class="doc"
952+
><p
953+
>Doc for: type instance Foo Y = X</p
954+
></td
949955
></tr
950956
><tr
951957
><td colspan="2"
@@ -1234,8 +1240,10 @@
12341240
> <a href="#" class="selflink"
12351241
>#</a
12361242
></td
1237-
><td class="doc empty"
1238-
></td
1243+
><td class="doc"
1244+
><p
1245+
>Doc for: type instance Foo Y = X</p
1246+
></td
12391247
></tr
12401248
><tr
12411249
><td colspan="2"
@@ -1274,8 +1282,10 @@
12741282
> <a href="#" class="selflink"
12751283
>#</a
12761284
></td
1277-
><td class="doc empty"
1278-
></td
1285+
><td class="doc"
1286+
><p
1287+
>Doc for: type instance Foo X = Y</p
1288+
></td
12791289
></tr
12801290
><tr
12811291
><td colspan="2"

html-test/ref/TypeFamilies2.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@
142142
> <a href="#" class="selflink"
143143
>#</a
144144
></td
145-
><td class="doc empty"
146-
></td
145+
><td class="doc"
146+
><p
147+
>Should be visible, but with a hidden right hand side</p
148+
></td
147149
></tr
148150
><tr
149151
><td colspan="2"
@@ -202,8 +204,10 @@
202204
> <a href="#" class="selflink"
203205
>#</a
204206
></td
205-
><td class="doc empty"
206-
></td
207+
><td class="doc"
208+
><p
209+
>Should be visible, but with a hidden right hand side</p
210+
></td
207211
></tr
208212
><tr
209213
><td colspan="2"
@@ -240,8 +244,10 @@
240244
> <a href="#" class="selflink"
241245
>#</a
242246
></td
243-
><td class="doc empty"
244-
></td
247+
><td class="doc"
248+
><p
249+
>External instance</p
250+
></td
245251
></tr
246252
><tr
247253
><td colspan="2"

0 commit comments

Comments
 (0)