@@ -73,32 +73,38 @@ getDocumentationsTryGhc env mod names = do
7373 res <- fun
7474 case res of
7575 Left _ -> return mempty
76- Right res -> fmap Map. fromList $ sequenceA $ unwrap <$> Map. toList res
76+ Right res -> fmap Map. fromList $ sequenceA $ uncurry unwrap <$> Map. toList res
7777 where
7878 fun :: IO (Either [FileDiagnostic ] (Map. Map Name (Either String (Maybe HsDocString , Map. Map Int HsDocString ))))
7979 fun = catchSrcErrors (hsc_dflags env) " docs" $ getDocsBatch env mod names
8080
81- unwrap :: (Name , Either a (Maybe HsDocString , b )) -> IO (Name , SpanDoc )
82- unwrap (name, Right (Just docs, _)) = (name,) . SpanDocString docs <$> getUris name
83- unwrap (name, _) = (name,) . SpanDocText mempty <$> getUris name
84-
85- -- Get the uris to the documentation and source html pages if they exist
86- getUris name = do
87- (docFu, srcFu) <-
88- case nameModule_maybe name of
89- Just mod -> liftIO $ do
90- doc <- toFileUriText $ lookupDocHtmlForModule env mod
91- src <- toFileUriText $ lookupSrcHtmlForModule env mod
92- return (doc, src)
93- Nothing -> pure (Nothing , Nothing )
94- let docUri = (<> " #" <> selector <> showNameWithoutUniques name) <$> docFu
95- srcUri = (<> " #" <> showNameWithoutUniques name) <$> srcFu
96- selector
97- | isValName name = " v:"
98- | otherwise = " t:"
99- return $ SpanDocUris docUri srcUri
100-
101- toFileUriText = (fmap . fmap ) (getUri . filePathToUri)
81+ unwrap :: Name -> Either a (Maybe HsDocString , b ) -> IO (Name , SpanDoc )
82+ unwrap name a = (name,) . extractDocString a <$> getSpanDocUris name
83+ where
84+ extractDocString :: Either b1 (Maybe HsDocString , b2 ) -> SpanDocUris -> SpanDoc
85+ -- 2021-11-17: FIXME: ArgDocs get dropped here - instead propagate them.
86+ extractDocString (Right (Just docs, _)) = SpanDocString docs
87+ extractDocString _ = SpanDocText mempty
88+
89+ -- | Get the uris to the documentation and source html pages if they exist
90+ getSpanDocUris :: Name -> IO SpanDocUris
91+ getSpanDocUris name = do
92+ (docFu, srcFu) <-
93+ case nameModule_maybe name of
94+ Just mod -> liftIO $ do
95+ doc <- toFileUriText $ lookupDocHtmlForModule env mod
96+ src <- toFileUriText $ lookupSrcHtmlForModule env mod
97+ return (doc, src)
98+ Nothing -> pure mempty
99+ let docUri = (<> " #" <> selector <> showNameWithoutUniques name) <$> docFu
100+ srcUri = (<> " #" <> showNameWithoutUniques name) <$> srcFu
101+ selector
102+ | isValName name = " v:"
103+ | otherwise = " t:"
104+ return $ SpanDocUris docUri srcUri
105+ where
106+ toFileUriText :: IO (Maybe FilePath ) -> IO (Maybe T. Text )
107+ toFileUriText = (fmap . fmap ) (getUri . filePathToUri)
102108
103109getDocumentation
104110 :: HasSrcSpan name
@@ -165,7 +171,7 @@ getDocumentation sources targetName = fromMaybe [] $ do
165171docHeaders :: [RealLocated AnnotationComment ]
166172 -> [T. Text ]
167173docHeaders = mapMaybe (\ (L _ x) -> wrk x)
168- where
174+ where
169175 wrk = \ case
170176 -- When `Opt_Haddock` is enabled.
171177 AnnDocCommentNext s -> Just $ T. pack s
0 commit comments