on master help sign in
Move catchSrcErrors over to GHC.Error
37689a8Neil Mitchell
src/Development/IDE/Core/Compile.hs−13
@@ -32,7 +32,6 @@ import Lexer
32import ErrUtils
32import ErrUtils
33
33
34import qualified GHC
34import qualified GHC
35−import Panic
36import GhcMonad
35import GhcMonad
37import GhcPlugins as GHC hiding (fst3, (<>))
36import GhcPlugins as GHC hiding (fst3, (<>))
38import qualified HeaderInfo as Hdr
37import qualified HeaderInfo as Hdr
@@ -344,15 +343,3 @@ parsePragmasIntoDynFlags fp contents = catchSrcErrors "pragmas" $ do
344 let opts = Hdr.getOptions dflags0 contents fp
343 let opts = Hdr.getOptions dflags0 contents fp
345 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
344 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
346 return dflags
345 return dflags
347−
348−-- | Run something in a Ghc monad and catch the errors (SourceErrors and
349−-- compiler-internal exceptions like Panic or InstallationError).
350−catchSrcErrors :: GhcMonad m => T.Text -> m a -> m (Either [FileDiagnostic] a)
351−catchSrcErrors fromWhere ghcM = do
352− dflags <- getDynFlags
353− handleGhcException (ghcExceptionToDiagnostics dflags) $
354− handleSourceError (sourceErrorToDiagnostics dflags) $
355− Right <$> ghcM
356− where
357− ghcExceptionToDiagnostics dflags = return . Left . diagFromGhcException fromWhere dflags
358− sourceErrorToDiagnostics dflags = return . Left . diagFromErrMsgs fromWhere dflags . srcErrorMessages
src/Development/IDE/GHC/Error.hs+17
@@ -8,6 +8,7 @@ module Development.IDE.GHC.Error
8 , diagFromString
8 , diagFromString
9 , diagFromStrings
9 , diagFromStrings
10 , diagFromGhcException
10 , diagFromGhcException
11+ , catchSrcErrors
11
12
12 -- * utilities working with spans
13 -- * utilities working with spans
13 , srcSpanToLocation
14 , srcSpanToLocation
@@ -23,6 +24,9 @@ import Development.IDE.GHC.Orphans()
23import qualified FastString as FS
24import qualified FastString as FS
24import GHC
25import GHC
25import Bag
26import Bag
27+import DynFlags
28+import HscTypes
29+import Panic
26import ErrUtils
30import ErrUtils
27import SrcLoc
31import SrcLoc
28import qualified Outputable as Out
32import qualified Outputable as Out
@@ -111,6 +115,19 @@ realSpan = \case
111 UnhelpfulSpan _ -> Nothing
115 UnhelpfulSpan _ -> Nothing
112
116
113
117
118+-- | Run something in a Ghc monad and catch the errors (SourceErrors and
119+-- compiler-internal exceptions like Panic or InstallationError).
120+catchSrcErrors :: GhcMonad m => T.Text -> m a -> m (Either [FileDiagnostic] a)
121+catchSrcErrors fromWhere ghcM = do
122+ dflags <- getDynFlags
123+ handleGhcException (ghcExceptionToDiagnostics dflags) $
124+ handleSourceError (sourceErrorToDiagnostics dflags) $
125+ Right <$> ghcM
126+ where
127+ ghcExceptionToDiagnostics dflags = return . Left . diagFromGhcException fromWhere dflags
128+ sourceErrorToDiagnostics dflags = return . Left . diagFromErrMsgs fromWhere dflags . srcErrorMessages
129+
130+
114diagFromGhcException :: T.Text -> DynFlags -> GhcException -> [FileDiagnostic]
131diagFromGhcException :: T.Text -> DynFlags -> GhcException -> [FileDiagnostic]
115diagFromGhcException diagSource dflags exc = diagFromString diagSource (noSpan "<Internal>") (showGHCE dflags exc)
132diagFromGhcException diagSource dflags exc = diagFromString diagSource (noSpan "<Internal>") (showGHCE dflags exc)
116
133