on master help sign in
Move catchSrcErrors over to GHC.Error
commit37689a808e28802b883d75bba8808bf8d026e8d4 authorNeil Mitchell <ndmitchell@gmail.com> dateWed 11 Sep 2019, 22:31 (7 years ago) parent18ee98f
2 files changed+17−13
src/Development/IDE/Core/Compile.hs−13 src/Development/IDE/GHC/Error.hs+17
src/Development/IDE/Core/Compile.hs−13
@@ -32,7 +32,6 @@ import Lexer
3232import ErrUtils
3333
3434import qualified GHC
35−import Panic
3635import GhcMonad
3736import GhcPlugins as GHC hiding (fst3, (<>))
3837import qualified HeaderInfo as Hdr
@@ -344,15 +343,3 @@ parsePragmasIntoDynFlags fp contents = catchSrcErrors "pragmas" $ do
344343 let opts = Hdr.getOptions dflags0 contents fp
345344 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
346345 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
88 , diagFromString
99 , diagFromStrings
1010 , diagFromGhcException
11+ , catchSrcErrors
1112
1213 -- * utilities working with spans
1314 , srcSpanToLocation
@@ -23,6 +24,9 @@ import Development.IDE.GHC.Orphans()
2324import qualified FastString as FS
2425import GHC
2526import Bag
27+import DynFlags
28+import HscTypes
29+import Panic
2630import ErrUtils
2731import SrcLoc
2832import qualified Outputable as Out
@@ -111,6 +115,19 @@ realSpan = \case
111115 UnhelpfulSpan _ -> Nothing
112116
113117
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+
114131diagFromGhcException :: T.Text -> DynFlags -> GhcException -> [FileDiagnostic]
115132diagFromGhcException diagSource dflags exc = diagFromString diagSource (noSpan "<Internal>") (showGHCE dflags exc)
116133