@@ -15,6 +15,7 @@ module Development.IDE.Spans.Documentation (
15
15
import Control.Monad
16
16
import Control.Monad.IO.Class
17
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
@@ -65,14 +65,14 @@ lookupKind env mod =
65
65
66
66
getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
67
67
-- 2021-11-17: FIXME: Code uses batch search for singleton & assumes that search always succeeds.
68
- getDocumentationTryGhc env mod n = fromJust . Map .lookup n <$> getDocumentationsTryGhc env mod [n]
68
+ getDocumentationTryGhc env mod n = fromJust . M .lookup n <$> getDocumentationsTryGhc env mod [n]
69
69
70
- getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (Map . Map Name SpanDoc )
70
+ getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (M . Map Name SpanDoc )
71
71
getDocumentationsTryGhc env mod names = do
72
72
res <- getDocsBatch env mod names
73
73
case res of
74
74
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
75
- Right res -> sequenceA $ Map . mapWithKey unwrap res
75
+ Right res -> sequenceA $ M . mapWithKey unwrap res
76
76
where
77
77
unwrap :: Name -> Either a (Maybe HsDocString , b ) -> IO SpanDoc
78
78
unwrap name a = extractDocString a <$> getSpanDocUris name
@@ -88,19 +88,21 @@ getDocumentationsTryGhc env mod names = do
88
88
(docFu, srcFu) <-
89
89
case nameModule_maybe name of
90
90
Just mod -> liftIO $ do
91
- doc <- toFileUriText $ lookupDocHtmlForModule env mod
92
- src <- toFileUriText $ lookupSrcHtmlForModule env mod
91
+ let
92
+ toUriFileText :: (HscEnv -> Module -> IO (Maybe FilePath )) -> IO (Maybe T. Text )
93
+ toUriFileText f = (fmap . fmap ) (getUri . filePathToUri) $ f env mod
94
+ doc <- toUriFileText lookupDocHtmlForModule
95
+ src <- toUriFileText lookupSrcHtmlForModule
93
96
return (doc, src)
94
97
Nothing -> pure mempty
95
- let docUri = (<> " #" <> selector <> showNameWithoutUniques name) <$> docFu
96
- srcUri = (<> " #" <> showNameWithoutUniques name) <$> srcFu
97
- selector
98
- | isValName name = " v:"
99
- | otherwise = " t:"
98
+ let
99
+ embelishUri :: Functor f => T. Text -> f T. Text -> f T. Text
100
+ embelishUri f = fmap (<> " #" <> f <> showNameWithoutUniques name)
101
+
102
+ docUri = embelishUri (bool " t:" " v:" $ isValName name) docFu
103
+ srcUri = embelishUri mempty srcFu
104
+
100
105
return $ SpanDocUris docUri srcUri
101
- where
102
- toFileUriText :: IO (Maybe FilePath ) -> IO (Maybe T. Text )
103
- toFileUriText = (fmap . fmap ) (getUri . filePathToUri)
104
106
105
107
getDocumentation
106
108
:: HasSrcSpan name
0 commit comments