Skip to content

Commit 2e306c9

Browse files
committed
ghcide: Core.Compile: getDocsBatch: give explicit GetDocsFailure
Showing error should be explicit, & conversion of error type should be a separate handling. This would also allow to establish proper processing for all these exception types.
1 parent 03e91bf commit 2e306c9

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import Development.IDE.GHC.Error
3838
import Development.IDE.GHC.Orphans ()
3939
import Development.IDE.GHC.Util
4040
import Development.IDE.GHC.Warnings
41-
import Development.IDE.Spans.Common
4241
import Development.IDE.Types.Diagnostics
4342
import Development.IDE.Types.Location
4443
import Development.IDE.Types.Options
@@ -78,7 +77,7 @@ import Control.Lens hiding (List)
7877
import Control.Monad.Except
7978
import Control.Monad.Extra
8079
import Control.Monad.Trans.Except
81-
import Data.Bifunctor (first, second)
80+
import Data.Bifunctor (second)
8281
import qualified Data.ByteString as BS
8382
import qualified Data.DList as DL
8483
import Data.IORef
@@ -109,6 +108,7 @@ import qualified Data.HashMap.Strict as HashMap
109108
import Data.IntMap (IntMap)
110109
import Data.Map (Map)
111110
import Data.Tuple.Extra (dupe)
111+
import Data.Either.Extra (maybeToEither)
112112
import Data.Unique as Unique
113113
import Development.IDE.Core.Tracing (withTrace)
114114
import Development.IDE.GHC.Compat.Util (emptyUDFM, plusUDFM_C)
@@ -1025,20 +1025,11 @@ getDocsBatch
10251025
:: HscEnv
10261026
-> Module -- ^ a moudle where the names are in scope
10271027
-> [Name]
1028-
-> IO (Either ErrorMessages (Map.Map Name (Either T.Text (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
1028+
-> IO (Either ErrorMessages (Map.Map Name (Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
10291029
getDocsBatch hsc_env _mod _names = do
10301030
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map.fromList <$> traverse findNameInfo _names
1031-
pure $ case res of
1032-
Just x -> pure $ fun x
1033-
Nothing -> Left errs
1034-
where
1035-
fun :: Map.Map Name (Either GetDocsFailure c) -> Map.Map Name (Either T.Text c)
1036-
fun =
1037-
Map.map fun1
1038-
where
1039-
fun1 :: Either GetDocsFailure c -> Either T.Text c
1040-
fun1 = first showGhc
1041-
1031+
pure $ maybeToEither errs res
1032+
where
10421033
findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))
10431034
findNameInfo name =
10441035
case nameModule_maybe name of

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ getDocumentationTryGhc env mod n = fromJust . Map.lookup n <$> getDocumentations
7474

7575
getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO (Map.Map Name SpanDoc)
7676
getDocumentationsTryGhc env mod names = do
77-
res <- fun
77+
res <- getDocsBatch env mod names
7878
case res of
7979
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
8080
Right res -> sequenceA $ Map.mapWithKey unwrap res
8181
where
82-
fun :: IO (Either ErrorMessages (Map.Map Name (Either T.Text (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
83-
fun = getDocsBatch env mod names
84-
8582
unwrap :: Name -> Either a (Maybe HsDocString, b) -> IO SpanDoc
8683
unwrap name a = extractDocString a <$> getSpanDocUris name
8784
where

0 commit comments

Comments
 (0)