@@ -15,6 +15,7 @@ module Development.IDE.Spans.Documentation (
1515import Control.Monad
1616import Control.Monad.IO.Class
1717import Control.Monad.Extra (findM )
18+ import Data.Bool (bool )
1819import Data.Either
1920import Data.Foldable
2021import Data.List.Extra
@@ -32,7 +33,6 @@ import System.Directory
3233import System.FilePath
3334
3435import Language.LSP.Types (filePathToUri , getUri )
35- import qualified Data.Map as Map
3636
3737mkDocMap
3838 :: HscEnv
@@ -65,14 +65,14 @@ lookupKind env mod =
6565
6666getDocumentationTryGhc :: HscEnv -> Module -> Name -> IO SpanDoc
6767-- 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]
6969
70- getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (Map . Map Name SpanDoc )
70+ getDocumentationsTryGhc :: HscEnv -> Module -> [Name ] -> IO (M . Map Name SpanDoc )
7171getDocumentationsTryGhc env mod names = do
7272 res <- getDocsBatch env mod names
7373 case res of
7474 Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
75- Right res -> sequenceA $ Map . mapWithKey unwrap res
75+ Right res -> sequenceA $ M . mapWithKey unwrap res
7676 where
7777 unwrap :: Name -> Either a (Maybe HsDocString , b ) -> IO SpanDoc
7878 unwrap name a = extractDocString a <$> getSpanDocUris name
@@ -88,19 +88,21 @@ getDocumentationsTryGhc env mod names = do
8888 (docFu, srcFu) <-
8989 case nameModule_maybe name of
9090 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
9396 return (doc, src)
9497 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+
100105 return $ SpanDocUris docUri srcUri
101- where
102- toFileUriText :: IO (Maybe FilePath ) -> IO (Maybe T. Text )
103- toFileUriText = (fmap . fmap ) (getUri . filePathToUri)
104106
105107getDocumentation
106108 :: HasSrcSpan name
0 commit comments