@@ -67,71 +67,23 @@ lookupKind :: HscEnv -> Module -> Name -> IO (Maybe TyThing)
67
67
lookupKind env mod =
68
68
fmap (fromRight Nothing ) . catchSrcErrors (hsc_dflags env) " span" . lookupName env mod
69
69
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
117
72
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
129
81
(docFu, srcFu) <-
130
82
case nameModule_maybe name of
131
83
Just mod -> liftIO $ do
132
84
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
135
87
doc <- toUriFileText lookupDocHtmlForModule
136
88
src <- toUriFileText lookupSrcHtmlForModule
137
89
return (doc, src)
@@ -145,6 +97,20 @@ getDocumentationsTryGhc env mod names = do
145
97
146
98
return $ SpanDocUris docUri srcUri
147
99
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
+
148
114
getDocumentation
149
115
:: HasSrcSpan name
150
116
=> [ParsedModule ] -- ^ All of the possible modules it could be defined in.
0 commit comments