@@ -13,8 +13,9 @@ module Development.IDE.Spans.Documentation (
13
13
) where
14
14
15
15
import Control.Monad
16
- import Control.Monad.Extra (findM )
17
16
import Control.Monad.IO.Class
17
+ import Control.Monad.Extra (findM )
18
+ import Data.Bool (bool )
18
19
import Data.Either
19
20
import Data.Foldable
20
21
import Data.List.Extra
@@ -32,7 +33,6 @@ import System.Directory
32
33
import System.FilePath
33
34
34
35
import Language.LSP.Types (filePathToUri , getUri )
35
- import qualified Data.Map as Map
36
36
37
37
mkDocMap
38
38
:: HscEnv
@@ -70,14 +70,14 @@ lookupKind env mod =
70
70
71
71
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
72
72
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
73
- getDocumentationTryGhc env mod n = fromJust . Map .lookup n <$> getDocumentationsTryGhc env mod [n]
73
+ getDocumentationTryGhc env mod n = fromJust . M .lookup n <$> getDocumentationsTryGhc env mod [n]
74
74
75
- getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (Map . Map Name SpanDoc )
75
+ getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (M . Map Name SpanDoc )
76
76
getDocumentationsTryGhc env mod names = do
77
77
res <- getDocsBatch env mod names
78
78
case res of
79
79
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
80
- Right res -> sequenceA $ Map . mapWithKey unwrap res
80
+ Right res -> sequenceA $ M . mapWithKey unwrap res
81
81
where
82
82
unwrap :: Name -> Either a (Maybe HsDocString , b ) -> IO SpanDoc
83
83
unwrap name a = extractDocString a <$> getSpanDocUris name
@@ -93,19 +93,21 @@ getDocumentationsTryGhc env mod names = do
93
93
(docFu, srcFu) <-
94
94
case nameModule_maybe name of
95
95
Just mod -> liftIO $ do
96
- doc <- toFileUriText $ lookupDocHtmlForModule env mod
97
- src <- toFileUriText $ lookupSrcHtmlForModule env mod
96
+ let
97
+ toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath )) -> IO (Maybe T. Text )
98
+ toUriFileText f = (fmap . fmap ) (getUri . filePathToUri) $ f env mod
99
+ doc <- toUriFileText lookupDocHtmlForModule
100
+ src <- toUriFileText lookupSrcHtmlForModule
98
101
return (doc, src)
99
102
Nothing -> pure mempty
100
- let docUri = (<> " #" <> selector <> showNameWithoutUniques name) <$> docFu
101
- srcUri = (<> " #" <> showNameWithoutUniques name) <$> srcFu
102
- selector
103
- | isValName name = " v:"
104
- | otherwise = " t:"
103
+ let
104
+ embelishUri :: Functor f => T. Text -> f T. Text -> f T. Text
105
+ embelishUri f = fmap (<> " #" <> f <> showNameWithoutUniques name)
106
+
107
+ docUri = embelishUri (bool " t:" " v:" $ isValName name) docFu
108
+ srcUri = embelishUri mempty srcFu
109
+
105
110
return $ SpanDocUris docUri srcUri
106
- where
107
- toFileUriText :: IO (Maybe FilePath ) -> IO (Maybe T. Text )
108
- toFileUriText = (fmap . fmap ) (getUri . filePathToUri)
109
111
110
112
getDocumentation
111
113
:: HasSrcSpan name
0 commit comments