Skip to content

Commit 5be04f7

Browse files
committed
ghcide: Documentation: form intoSpanDoc
1 parent 0698dde commit 5be04f7

File tree

1 file changed

+27
-60
lines changed

1 file changed

+27
-60
lines changed

ghcide/src/Development/IDE/Spans/Documentation.hs

+27-60
Original file line numberDiff line numberDiff line change
@@ -62,71 +62,23 @@ lookupKind :: HscEnv -> Module -> Name -> IO (Maybe TyThing)
6262
lookupKind env mod =
6363
fmap (fromRight Nothing) . catchSrcErrors (hsc_dflags env) "span" . lookupName env mod
6464

65-
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
66-
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
67-
getDocumentationTryGhc env mod = fun
68-
where
69-
fun :: Name -> IO SpanDoc
70-
fun name = do
71-
res <- getDocsNonInteractive env mod name
72-
case res of
73-
Left _ -> pure emptySpanDoc -- catchSrcErrors (hsc_dflags env) "docs"
74-
Right res -> uncurry unwrap res
75-
where
76-
unwrap :: Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
77-
unwrap name a = extractDocString a <$> getSpanDocUris name
78-
where
79-
extractDocString :: Either b1 (Maybe HsDocString, b2) -> SpanDocUris -> SpanDoc
80-
-- 2021-11-17: FIXME: ArgDocs get dropped here - instead propagate them.
81-
extractDocString (Right (Just docs, _)) = SpanDocString docs
82-
extractDocString _ = SpanDocText mempty
83-
84-
-- | Get the uris to the documentation and source html pages if they exist
85-
getSpanDocUris :: Name -> IO SpanDocUris
86-
getSpanDocUris name = do
87-
(docFu, srcFu) <-
88-
case nameModule_maybe name of
89-
Just mod -> liftIO $ do
90-
let
91-
toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath)) -> IO (Maybe T.Text)
92-
toUriFileText f = (fmap . fmap) (getUri . filePathToUri) $ f env mod
93-
doc <- toUriFileText lookupDocHtmlForModule
94-
src <- toUriFileText lookupSrcHtmlForModule
95-
return (doc, src)
96-
Nothing -> pure mempty
97-
let
98-
embelishUri :: Functor f => T.Text -> f T.Text -> f T.Text
99-
embelishUri f = fmap (<> "#" <> f <> showNameWithoutUniques name)
100-
101-
docUri = embelishUri (bool "t:" "v:" $ isValName name) docFu
102-
srcUri = embelishUri mempty srcFu
103-
104-
return $ SpanDocUris docUri srcUri
105-
106-
getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO (M.Map Name SpanDoc)
107-
getDocumentationsTryGhc env mod names = do
108-
res <- getDocsBatch env mod names
109-
case res of
110-
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
111-
Right res -> sequenceA $ M.mapWithKey unwrap res
65+
intoSpanDoc :: HscEnv -> Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
66+
intoSpanDoc env name a = extractDocString a <$> getSpanDocUris name
11267
where
113-
unwrap :: Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
114-
unwrap name a = extractDocString a <$> getSpanDocUris name
115-
where
116-
extractDocString :: Either b1 (Maybe HsDocString, b2) -> SpanDocUris -> SpanDoc
117-
-- 2021-11-17: FIXME: ArgDocs get dropped here - instead propagate them.
118-
extractDocString (Right (Just docs, _)) = SpanDocString docs
119-
extractDocString _ = SpanDocText mempty
120-
121-
-- | Get the uris to the documentation and source html pages if they exist
122-
getSpanDocUris :: Name -> IO SpanDocUris
123-
getSpanDocUris name = do
68+
extractDocString :: Either b1 (Maybe HsDocString, b2) -> SpanDocUris -> SpanDoc
69+
-- 2021-11-17: FIXME: ArgDocs get dropped here - instead propagate them.
70+
extractDocString (Right (Just docs, _)) = SpanDocString docs
71+
extractDocString _ = SpanDocText mempty
72+
73+
-- | Get the uris to the documentation and source html pages if they exist
74+
getSpanDocUris :: Name -> IO SpanDocUris
75+
getSpanDocUris name = do
12476
(docFu, srcFu) <-
12577
case nameModule_maybe name of
12678
Just mod -> liftIO $ do
12779
let
128-
toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath)) -> IO (Maybe T.Text)
129-
toUriFileText f = (fmap . fmap) (getUri . filePathToUri) $ f env mod
80+
toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath)) -> IO (Maybe T.Text)
81+
toUriFileText f = (fmap . fmap) (getUri . filePathToUri) $ f env mod
13082
doc <- toUriFileText lookupDocHtmlForModule
13183
src <- toUriFileText lookupSrcHtmlForModule
13284
return (doc, src)
@@ -140,6 +92,21 @@ getDocumentationsTryGhc env mod names = do
14092

14193
return $ SpanDocUris docUri srcUri
14294

95+
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
96+
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
97+
getDocumentationTryGhc env mod name = do
98+
res <- getDocsNonInteractive env mod name
99+
case res of
100+
Left _ -> pure emptySpanDoc -- catchSrcErrors (hsc_dflags env) "docs"
101+
Right res -> uncurry (intoSpanDoc env) res
102+
103+
getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO (M.Map Name SpanDoc)
104+
getDocumentationsTryGhc env mod names = do
105+
res <- getDocsBatch env mod names
106+
case res of
107+
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
108+
Right res -> sequenceA $ M.mapWithKey (intoSpanDoc env) res
109+
143110
getDocumentation
144111
:: HasSrcSpan name
145112
=> [ParsedModule] -- ^ All of the possible modules it could be defined in.

0 commit comments

Comments
 (0)