Skip to content

Commit 37689a8

Browse files
committed
Move catchSrcErrors over to GHC.Error
1 parent 18ee98f commit 37689a8

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/Development/IDE/Core/Compile.hs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import Lexer
3232
import ErrUtils
3333

3434
import qualified GHC
35-
import Panic
3635
import GhcMonad
3736
import GhcPlugins as GHC hiding (fst3, (<>))
3837
import 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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
2324
import qualified FastString as FS
2425
import GHC
2526
import Bag
27+
import DynFlags
28+
import HscTypes
29+
import Panic
2630
import ErrUtils
2731
import SrcLoc
2832
import 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+
114131
diagFromGhcException :: T.Text -> DynFlags -> GhcException -> [FileDiagnostic]
115132
diagFromGhcException diagSource dflags exc = diagFromString diagSource (noSpan "<Internal>") (showGHCE dflags exc)
116133

0 commit comments

Comments
 (0)