@@ -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 )
@@ -65,7 +64,44 @@ lookupKind env mod =
65
64
66
65
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
67
66
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
68
- getDocumentationTryGhc env mod n = fromJust . M. lookup n <$> getDocumentationsTryGhc env mod [n]
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
69
105
70
106
getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (M. Map Name SpanDoc )
71
107
getDocumentationsTryGhc env mod names = do
0 commit comments