@@ -6,12 +6,14 @@ import Control.Exception
6
6
import Control.Monad.IO.Class
7
7
import qualified Data.Text as T
8
8
import Data.Vinyl
9
+ import Haskell.Ide.Engine.MonadFunctions
9
10
import Haskell.Ide.Engine.PluginDescriptor
10
11
import Haskell.Ide.Engine.PluginUtils
11
12
import Haskell.Ide.Engine.SemanticTypes
12
13
import qualified Language.Haskell.GhcMod as GM (defaultOptions )
13
14
import Language.Haskell.HLint
14
15
import System.Directory
16
+ import System.Exit
15
17
import System.FilePath.Posix
16
18
import System.IO
17
19
import System.IO.Extra
@@ -53,17 +55,29 @@ applyOneCmd = CmdSync $ \_ctxs req -> do
53
55
Right _ -> return $ IdeResponseError (IdeError InternalError
54
56
" ApplyRefactPlugin.demoteCmd: ghc’s exhaustiveness checker is broken" Nothing )
55
57
56
- -- demote :: RefactSettings -> GM.Options -> FilePath -> SimpPos -> IO [FilePath]
57
58
58
59
-- ---------------------------------------------------------------------
59
60
60
- applyHint :: FilePath -> Pos -> IO HieDiff
61
+ applyHint :: FilePath -> Pos -> IO ( Either t HieDiff )
61
62
applyHint file pos = do
62
63
withTempFile $ \ f -> do
63
- let opts = " --output " ++ f
64
- hlint [" --refactor" , " -" , " --refactor-options=" ++ show opts, file]
65
- diff <- makeDiffResult file f
66
- return diff
64
+ absFile <- makeAbsolute file
65
+ -- hlint /tmp/Foo.hs --refactor --refactor-options="-o /tmp/Bar.hs --pos 2,8"
66
+
67
+ -- let opts = "-o " ++ f
68
+ let opts = " -o /tmp/BarOne.hs"
69
+ -- let hlintOpts = [absFile, "--refactor", "--refactor-options=" ++ show opts ]
70
+ let hlintOpts = [" /tmp/Foo.hs" , " --refactor" , " --refactor-options=" ++ opts ]
71
+ -- let hlintOpts = ["/tmp/Foo.hs", "--refactor" ]
72
+ logm $ " applyHint=" ++ show hlintOpts
73
+ res <- catchException $ hlint hlintOpts
74
+ logm $ " applyHint:res=" ++ show res
75
+ case res of
76
+ Left ExitSuccess -> do
77
+ diff <- makeDiffResult file f
78
+ logm $ " applyHint:diff=" ++ show diff
79
+ return $ Right diff
80
+ _ -> return res
67
81
68
82
-- ---------------------------------------------------------------------
69
83
0 commit comments