Skip to content

Commit b5dd8e8

Browse files
committed
ghcide: Spans.Documentation: getDocumentationsTryGhc: clean-up
1 parent aef0997 commit b5dd8e8

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

+1
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ getDocsBatch hsc_env _mod _names = do
981981
}
982982
<- loadModuleInterface "getModuleInterface" mod
983983
pure . (name,) $
984+
-- 2021-11-17: NOTE: one does not simply check into Mordor (not 1 mode)
984985
if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
985986
then Left $ NoDocsInIface mod $ isCompiled name
986987
else Right (Map.lookup name dmap, Map.lookup name amap)

ghcide/src/Development/IDE/Spans/Common.hs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ showGhc = showSD . ppr
4040
showSD :: SDoc -> T.Text
4141
showSD = T.pack . unsafePrintSDoc
4242

43+
-- | Print name dropping unique tagging.
4344
showNameWithoutUniques :: Outputable a => a -> T.Text
4445
showNameWithoutUniques = T.pack . printNameWithoutUniques
4546

ghcide/src/Development/IDE/Spans/Documentation.hs

+16-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Development.IDE.Spans.Documentation (
1515
import Control.Monad
1616
import Control.Monad.IO.Class
1717
import Control.Monad.Extra (findM)
18+
import Data.Bool (bool)
1819
import Data.Either
1920
import Data.Foldable
2021
import Data.List.Extra
@@ -32,7 +33,6 @@ import System.Directory
3233
import System.FilePath
3334

3435
import Language.LSP.Types (filePathToUri, getUri)
35-
import qualified Data.Map as Map
3636

3737
mkDocMap
3838
:: HscEnv
@@ -65,14 +65,14 @@ lookupKind env mod =
6565

6666
getDocumentationTryGhc :: 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)
7171
getDocumentationsTryGhc 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

105107
getDocumentation
106108
:: HasSrcSpan name

0 commit comments

Comments
 (0)