@@ -20,6 +20,7 @@ module Ide.Plugin.Hlint
20
20
import Refact.Apply
21
21
import Control.Arrow ((&&&) )
22
22
import Control.DeepSeq
23
+ import Control.Exception
23
24
import Control.Lens ((^.) )
24
25
import Control.Monad
25
26
import Control.Monad.IO.Class
@@ -37,7 +38,6 @@ import Development.IDE.Core.Rules (defineNoFile)
37
38
import Development.IDE.Core.Shake (getDiagnostics )
38
39
39
40
#ifdef HLINT_ON_GHC_LIB
40
- import Control.Exception
41
41
import Data.List (nub )
42
42
import "ghc-lib" GHC hiding (DynFlags (.. ), ms_hspp_opts )
43
43
import "ghc-lib-parser" GHC.LanguageExtensions (Extension )
@@ -351,6 +351,9 @@ applyHint ide nfp mhint =
351
351
runExceptT $ do
352
352
let runAction' :: Action a -> IO a
353
353
runAction' = runAction " applyHint" ide
354
+ let errorHandlers = [ Handler $ \ e -> return (Left (show (e :: IOException )))
355
+ , Handler $ \ e -> return (Left (show (e :: ErrorCall )))
356
+ ]
354
357
ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas nfp
355
358
let ideas' = maybe ideas (`filterIdeas` ideas) mhint
356
359
let commands = map ideaRefactoring ideas'
@@ -388,10 +391,8 @@ applyHint ide nfp mhint =
388
391
-- We have to reparse extensions to remove the invalid ones
389
392
let (enabled, disabled, _invalid) = parseExtensions $ map show exts
390
393
let refactExts = map show $ enabled ++ disabled
391
- (Right <$> applyRefactorings Nothing commands temp refactExts) `catches`
392
- [ Handler $ \ e -> return (Left (show (e :: IOException )))
393
- , Handler $ \ e -> return (Left (show (e :: ErrorCall )))
394
- ]
394
+ (Right <$> applyRefactorings Nothing commands temp refactExts)
395
+ `catches` errorHandlers
395
396
#else
396
397
mbParsedModule <- liftIO $ runAction' $ getParsedModule nfp
397
398
res <-
@@ -404,7 +405,8 @@ applyHint ide nfp mhint =
404
405
let dflags = ms_hspp_opts modsum
405
406
(anns', modu') <-
406
407
ExceptT $ return $ postParseTransform (Right (anns, [] , dflags, modu)) normalLayout
407
- liftIO (Right <$> applyRefactorings' Nothing commands anns' modu')
408
+ liftIO $ (Right <$> applyRefactorings' Nothing commands anns' modu')
409
+ `catches` errorHandlers
408
410
#endif
409
411
case res of
410
412
Right appliedFile -> do
0 commit comments