@@ -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 )
@@ -350,6 +350,9 @@ applyHint ide nfp mhint =
350
350
runExceptT $ do
351
351
let runAction' :: Action a -> IO a
352
352
runAction' = runAction " applyHint" ide
353
+ let errorHandlers = [ Handler $ \ e -> return (Left (show (e :: IOException )))
354
+ , Handler $ \ e -> return (Left (show (e :: ErrorCall )))
355
+ ]
353
356
ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas nfp
354
357
let ideas' = maybe ideas (`filterIdeas` ideas) mhint
355
358
let commands = map ideaRefactoring ideas'
@@ -387,10 +390,8 @@ applyHint ide nfp mhint =
387
390
-- We have to reparse extensions to remove the invalid ones
388
391
let (enabled, disabled, _invalid) = parseExtensions $ map show exts
389
392
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
394
395
#else
395
396
mbParsedModule <- liftIO $ runAction' $ getParsedModule nfp
396
397
res <-
@@ -403,7 +404,8 @@ applyHint ide nfp mhint =
403
404
let dflags = ms_hspp_opts modsum
404
405
(anns', modu') <-
405
406
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
407
409
#endif
408
410
case res of
409
411
Right appliedFile -> do
0 commit comments