@@ -12,7 +12,6 @@ module Development.IDE.Spans.Documentation (
12
12
, mkDocMap
13
13
) where
14
14
15
- import Control.Monad
16
15
import Control.Monad.IO.Class
17
16
import Control.Monad.Extra (findM )
18
17
import Data.Bool (bool )
@@ -70,7 +69,44 @@ lookupKind env mod =
70
69
71
70
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
72
71
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
73
- getDocumentationTryGhc env mod n = fromJust . M. lookup n <$> getDocumentationsTryGhc env mod [n]
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
74
110
75
111
getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (M. Map Name SpanDoc )
76
112
getDocumentationsTryGhc env mod names = do
0 commit comments