Skip to content

Commit 6505233

Browse files
committed
Improve error handling for initPlugins
1 parent 2084203 commit 6505233

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,25 @@ typecheckModule :: IdeDefer
149149
typecheckModule (IdeDefer defer) hsc keep_lbls pm = do
150150
let modSummary = pm_mod_summary pm
151151
dflags = ms_hspp_opts modSummary
152-
modSummary' <- initPlugins hsc modSummary
153-
(warnings, etcm) <- withWarnings "typecheck" $ \tweak ->
154-
let
155-
session = tweak (hscSetFlags dflags hsc)
156-
-- TODO: maybe settings ms_hspp_opts is unnecessary?
157-
mod_summary'' = modSummary' { ms_hspp_opts = hsc_dflags session}
158-
in
159-
catchSrcErrors (hsc_dflags hsc) "typecheck" $ do
160-
tcRnModule session keep_lbls $ demoteIfDefer pm{pm_mod_summary = mod_summary''}
161-
let errorPipeline = unDefer . hideDiag dflags . tagDiag
162-
diags = map errorPipeline warnings
163-
deferedError = any fst diags
164-
case etcm of
165-
Left errs -> return ((map snd diags) ++ errs, Nothing)
166-
Right tcm -> return (map snd diags, Just $ tcm{tmrDeferedError = deferedError})
152+
mmodSummary' <- catchSrcErrors (hsc_dflags hsc) "typecheck (initialize plugins)"
153+
(initPlugins hsc modSummary)
154+
case mmodSummary' of
155+
Left errs -> return (errs, Nothing)
156+
Right modSummary' -> do
157+
(warnings, etcm) <- withWarnings "typecheck" $ \tweak ->
158+
let
159+
session = tweak (hscSetFlags dflags hsc)
160+
-- TODO: maybe settings ms_hspp_opts is unnecessary?
161+
mod_summary'' = modSummary' { ms_hspp_opts = hsc_dflags session}
162+
in
163+
catchSrcErrors (hsc_dflags hsc) "typecheck" $ do
164+
tcRnModule session keep_lbls $ demoteIfDefer pm{pm_mod_summary = mod_summary''}
165+
let errorPipeline = unDefer . hideDiag dflags . tagDiag
166+
diags = map errorPipeline warnings
167+
deferedError = any fst diags
168+
case etcm of
169+
Left errs -> return ((map snd diags) ++ errs, Nothing)
170+
Right tcm -> return (map snd diags, Just $ tcm{tmrDeferedError = deferedError})
167171
where
168172
demoteIfDefer = if defer then demoteTypeErrorsToWarnings else id
169173

0 commit comments

Comments
 (0)