Skip to content

Commit 39ad133

Browse files
committed
ghcide: Documentation: form intoSpanDoc
1 parent ffbe9a8 commit 39ad133

File tree

1 file changed

+26
-60
lines changed

1 file changed

+26
-60
lines changed

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

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -67,71 +67,23 @@ lookupKind :: HscEnv -> Module -> Name -> IO (Maybe TyThing)
6767
lookupKind env mod =
6868
fmap (fromRight Nothing) . catchSrcErrors (hsc_dflags env) "span" . lookupName env mod
6969

70-
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
71-
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
72-
getDocumentationTryGhc env mod = fun
73-
where
74-
fun :: Name -> IO SpanDoc
75-
fun name = do
76-
res <- getDocsNonInteractive env mod name
77-
case res of
78-
Left _ -> pure emptySpanDoc -- catchSrcErrors (hsc_dflags env) "docs"
79-
Right res -> uncurry unwrap res
80-
where
81-
unwrap :: Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
82-
unwrap name a = 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-
let
96-
toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath)) -> IO (Maybe T.Text)
97-
toUriFileText f = (fmap . fmap) (getUri . filePathToUri) $ f env mod
98-
doc <- toUriFileText lookupDocHtmlForModule
99-
src <- toUriFileText lookupSrcHtmlForModule
100-
return (doc, src)
101-
Nothing -> pure mempty
102-
let
103-
embelishUri :: Functor f => T.Text -> f T.Text -> f T.Text
104-
embelishUri f = fmap (<> "#" <> f <> showNameWithoutUniques name)
105-
106-
docUri = embelishUri (bool "t:" "v:" $ isValName name) docFu
107-
srcUri = embelishUri mempty srcFu
108-
109-
return $ SpanDocUris docUri srcUri
110-
111-
getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO (M.Map Name SpanDoc)
112-
getDocumentationsTryGhc env mod names = do
113-
res <- getDocsBatch env mod names
114-
case res of
115-
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
116-
Right res -> sequenceA $ M.mapWithKey unwrap res
70+
intoSpanDoc :: HscEnv -> Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
71+
intoSpanDoc env name a = extractDocString a <$> getSpanDocUris name
11772
where
118-
unwrap :: Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
119-
unwrap name a = extractDocString a <$> getSpanDocUris name
120-
where
121-
extractDocString :: Either b1 (Maybe HsDocString, b2) -> SpanDocUris -> SpanDoc
122-
-- 2021-11-17: FIXME: ArgDocs get dropped here - instead propagate them.
123-
extractDocString (Right (Just docs, _)) = SpanDocString docs
124-
extractDocString _ = SpanDocText mempty
125-
126-
-- | Get the uris to the documentation and source html pages if they exist
127-
getSpanDocUris :: Name -> IO SpanDocUris
128-
getSpanDocUris name = do
73+
extractDocString :: Either b1 (Maybe HsDocString, b2) -> SpanDocUris -> SpanDoc
74+
-- 2021-11-17: FIXME: ArgDocs get dropped here - instead propagate them.
75+
extractDocString (Right (Just docs, _)) = SpanDocString docs
76+
extractDocString _ = SpanDocText mempty
77+
78+
-- | Get the uris to the documentation and source html pages if they exist
79+
getSpanDocUris :: Name -> IO SpanDocUris
80+
getSpanDocUris name = do
12981
(docFu, srcFu) <-
13082
case nameModule_maybe name of
13183
Just mod -> liftIO $ do
13284
let
133-
toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath)) -> IO (Maybe T.Text)
134-
toUriFileText f = (fmap . fmap) (getUri . filePathToUri) $ f env mod
85+
toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath)) -> IO (Maybe T.Text)
86+
toUriFileText f = (fmap . fmap) (getUri . filePathToUri) $ f env mod
13587
doc <- toUriFileText lookupDocHtmlForModule
13688
src <- toUriFileText lookupSrcHtmlForModule
13789
return (doc, src)
@@ -145,6 +97,20 @@ getDocumentationsTryGhc env mod names = do
14597

14698
return $ SpanDocUris docUri srcUri
14799

100+
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
101+
getDocumentationTryGhc env mod name = do
102+
res <- getDocsNonInteractive env mod name
103+
case res of
104+
Left _ -> pure emptySpanDoc
105+
Right res -> uncurry (intoSpanDoc env) res
106+
107+
getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO (M.Map Name SpanDoc)
108+
getDocumentationsTryGhc env mod names = do
109+
res <- getDocsBatch env mod names
110+
case res of
111+
Left _ -> return mempty
112+
Right res -> sequenceA $ M.mapWithKey (intoSpanDoc env) res
113+
148114
getDocumentation
149115
:: HasSrcSpan name
150116
=> [ParsedModule] -- ^ All of the possible modules it could be defined in.

0 commit comments

Comments
 (0)