@@ -20,6 +20,7 @@ module Ide.Plugin.Hlint
2020import Refact.Apply
2121import Control.Arrow ((&&&) )
2222import Control.DeepSeq
23+ import Control.Exception
2324import Control.Lens ((^.) )
2425import Control.Monad
2526import Control.Monad.IO.Class
@@ -37,7 +38,6 @@ import Development.IDE.Core.Rules (defineNoFile)
3738import Development.IDE.Core.Shake (getDiagnostics )
3839
3940#ifdef HLINT_ON_GHC_LIB
40- import Control.Exception
4141import Data.List (nub )
4242import "ghc-lib" GHC hiding (DynFlags (.. ), ms_hspp_opts )
4343import "ghc-lib-parser" GHC.LanguageExtensions (Extension )
@@ -350,6 +350,9 @@ applyHint ide nfp mhint =
350350 runExceptT $ do
351351 let runAction' :: Action a -> IO a
352352 runAction' = runAction " applyHint" ide
353+ let errorHandlers = [ Handler $ \ e -> return (Left (show (e :: IOException )))
354+ , Handler $ \ e -> return (Left (show (e :: ErrorCall )))
355+ ]
353356 ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas nfp
354357 let ideas' = maybe ideas (`filterIdeas` ideas) mhint
355358 let commands = map ideaRefactoring ideas'
@@ -387,10 +390,8 @@ applyHint ide nfp mhint =
387390 -- We have to reparse extensions to remove the invalid ones
388391 let (enabled, disabled, _invalid) = parseExtensions $ map show exts
389392 let refactExts = map show $ enabled ++ disabled
390- (Right <$> applyRefactorings Nothing commands temp refactExts) `catches`
391- [ Handler $ \ e -> return (Left (show (e :: IOException )))
392- , Handler $ \ e -> return (Left (show (e :: ErrorCall )))
393- ]
393+ (Right <$> applyRefactorings Nothing commands temp refactExts)
394+ `catches` errorHandlers
394395#else
395396 mbParsedModule <- liftIO $ runAction' $ getParsedModule nfp
396397 res <-
@@ -403,7 +404,8 @@ applyHint ide nfp mhint =
403404 let dflags = ms_hspp_opts modsum
404405 (anns', modu') <-
405406 ExceptT $ return $ postParseTransform (Right (anns, [] , dflags, modu)) normalLayout
406- liftIO (Right <$> applyRefactorings' Nothing commands anns' modu')
407+ liftIO $ (Right <$> applyRefactorings' Nothing commands anns' modu')
408+ `catches` errorHandlers
407409#endif
408410 case res of
409411 Right appliedFile -> do
0 commit comments