aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock/Interface/Rn.hs
diff options
context:
space:
mode:
authorDavid Waern <david.waern@gmail.com>2011-11-26 04:20:12 +0100
committerDavid Waern <david.waern@gmail.com>2011-11-26 04:20:12 +0100
commit3ebdc745d7bc79307986332dc71f3495099b4579 (patch)
treec1e15b26b65e079a52000b37791077eee687d659 /src/Haddock/Interface/Rn.hs
parentc3278a9d3c17ea0929d39116e431a2839bb845ca (diff)
Give preference to type over data constructors for doc comment links at renaming time.
Previously this was done in the backends. Also, warn when a doc comment refers to something that is in scope but which we don't have the .haddock file for. These changes mean we can make DocIdentifier [a] into DocIdentifier a.
Diffstat (limited to 'src/Haddock/Interface/Rn.hs')
-rw-r--r--src/Haddock/Interface/Rn.hs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Haddock/Interface/Rn.hs b/src/Haddock/Interface/Rn.hs
index d63524b6..57704db7 100644
--- a/src/Haddock/Interface/Rn.hs
+++ b/src/Haddock/Interface/Rn.hs
@@ -5,7 +5,7 @@ import Haddock.Types
import RnEnv ( dataTcOccs )
import RdrName ( RdrName, gre_name, GlobalRdrEnv, lookupGRE_RdrName )
-import Name ( Name )
+import Name ( Name, isTyConName )
import Outputable ( ppr, showSDoc )
rnHaddockModInfo :: GlobalRdrEnv -> HaddockModInfo RdrName -> HaddockModInfo Name
@@ -13,10 +13,6 @@ rnHaddockModInfo gre hmod =
let desc = hmi_description hmod
in hmod { hmi_description = fmap (rnDoc gre) desc }
-ids2string :: [RdrName] -> String
-ids2string [] = []
-ids2string (x:_) = showSDoc $ ppr x
-
data Id x = Id {unId::x}
instance Monad Id where (Id v)>>=f = f v; return = Id
@@ -38,13 +34,16 @@ rnDoc gre = unId . do_rn
doc' <- do_rn doc
return (DocParagraph doc')
- DocIdentifier ids -> do
- let choices = concatMap dataTcOccs ids
+ DocIdentifier x -> do
+ let choices = dataTcOccs x
let gres = concatMap (\rdrName ->
map gre_name (lookupGRE_RdrName rdrName gre)) choices
- case gres of
- [] -> return (DocMonospaced (DocString (ids2string ids)))
- ids' -> return (DocIdentifier ids')
+ return $ case gres of
+ [] -> DocMonospaced (DocString (showSDoc $ ppr x)) -- TODO: DocIdentifierRdrName
+ [a] -> DocIdentifier a
+ a:b:_ | isTyConName a -> DocIdentifier a | otherwise -> DocIdentifier b
+ -- If an id can refer to multiple things, we give precedence to type
+ -- constructors.
DocModule str -> return (DocModule str)