@@ -62,71 +62,23 @@ lookupKind :: HscEnv -> Module -> Name -> IO (Maybe TyThing)
62
62
lookupKind env mod =
63
63
fmap (fromRight Nothing ) . catchSrcErrors (hsc_dflags env) " span" . lookupName env mod
64
64
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
112
67
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
124
76
(docFu, srcFu) <-
125
77
case nameModule_maybe name of
126
78
Just mod -> liftIO $ do
127
79
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
130
82
doc <- toUriFileText lookupDocHtmlForModule
131
83
src <- toUriFileText lookupSrcHtmlForModule
132
84
return (doc, src)
@@ -140,6 +92,21 @@ getDocumentationsTryGhc env mod names = do
140
92
141
93
return $ SpanDocUris docUri srcUri
142
94
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
+
143
110
getDocumentation
144
111
:: HasSrcSpan name
145
112
=> [ParsedModule ] -- ^ All of the possible modules it could be defined in.
0 commit comments