@@ -30,8 +30,8 @@ applyRefactDescriptor = PluginDescriptor
30
30
buildCommand applyOneCmd " applyOne" " Apply a single hint"
31
31
[" .hs" ] [CtxPoint ] []
32
32
33
- -- , buildCommand applyAllCmd "applyAll" "Apply all hints to the file"
34
- -- [".hs"] [CtxFile] []
33
+ , buildCommand applyAllCmd " applyAll" " Apply all hints to the file"
34
+ [" .hs" ] [CtxFile ] []
35
35
36
36
]
37
37
, pdExposedServices = []
@@ -45,39 +45,55 @@ applyOneCmd = CmdSync $ \_ctxs req -> do
45
45
case getParams (IdFile " file" :& IdPos " start_pos" :& RNil ) req of
46
46
Left err -> return err
47
47
Right (ParamFile fileName :& ParamPos pos :& RNil ) -> do
48
- res <- liftIO $ catchException $ applyHint (T. unpack fileName) pos
48
+ res <- liftIO $ applyHint (T. unpack fileName) ( Just pos)
49
49
case res of
50
50
Left err -> return $ IdeResponseFail (IdeError PluginError
51
51
(T. pack $ " applyOne: " ++ show err) Nothing )
52
- Right fs -> do
53
- -- r <- liftIO $ makeRefactorResult [fs]
54
- return (IdeResponseOk fs)
52
+ Right fs -> return (IdeResponseOk fs)
55
53
Right _ -> return $ IdeResponseError (IdeError InternalError
56
- " ApplyRefactPlugin.demoteCmd : ghc’s exhaustiveness checker is broken" Nothing )
54
+ " ApplyRefactPlugin.applyOneCmd : ghc’s exhaustiveness checker is broken" Nothing )
57
55
58
56
59
57
-- ---------------------------------------------------------------------
60
58
61
- applyHint :: FilePath -> Pos -> IO (Either t HieDiff )
62
- applyHint file pos = do
59
+ applyAllCmd :: CommandFunc HieDiff
60
+ applyAllCmd = CmdSync $ \ _ctxs req -> do
61
+ case getParams (IdFile " file" :& RNil ) req of
62
+ Left err -> return err
63
+ Right (ParamFile fileName :& RNil ) -> do
64
+ res <- liftIO $ applyHint (T. unpack fileName) Nothing
65
+ case res of
66
+ Left err -> return $ IdeResponseFail (IdeError PluginError
67
+ (T. pack $ " applyOne: " ++ show err) Nothing )
68
+ Right fs -> return (IdeResponseOk fs)
69
+ Right _ -> return $ IdeResponseError (IdeError InternalError
70
+ " ApplyRefactPlugin.applyOneCmd: ghc’s exhaustiveness checker is broken" Nothing )
71
+
72
+
73
+ -- ---------------------------------------------------------------------
74
+
75
+ applyHint :: FilePath -> Maybe Pos -> IO (Either String HieDiff )
76
+ applyHint file mpos = do
63
77
withTempFile $ \ f -> do
64
- absFile <- makeAbsolute file
78
+ -- absFile <- makeAbsolute file
65
79
-- hlint /tmp/Foo.hs --refactor --refactor-options="-o /tmp/Bar.hs --pos 2,8"
66
80
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" ]
81
+ let
82
+ optsf = " -o " ++ f
83
+ opts = case mpos of
84
+ Nothing -> optsf
85
+ Just (r,c) -> optsf ++ " --pos " ++ show r ++ " ," ++ show c
86
+ let hlintOpts = [file, " --refactor" , " --refactor-options=" ++ opts ]
72
87
logm $ " applyHint=" ++ show hlintOpts
73
88
res <- catchException $ hlint hlintOpts
74
89
logm $ " applyHint:res=" ++ show res
75
90
case res of
76
- Left ExitSuccess -> do
91
+ Left " ExitSuccess" -> do
77
92
diff <- makeDiffResult file f
78
93
logm $ " applyHint:diff=" ++ show diff
79
94
return $ Right diff
80
- _ -> return res
95
+ Left x -> return $ Left (show x)
96
+ Right x -> return $ Left (show x)
81
97
82
98
-- ---------------------------------------------------------------------
83
99
@@ -86,7 +102,8 @@ makeDiffResult orig new = do
86
102
(HieDiff f s d) <- diffFiles orig new
87
103
f' <- liftIO $ makeRelativeToCurrentDirectory f
88
104
s' <- liftIO $ makeRelativeToCurrentDirectory s
89
- return (HieDiff f' s' d)
105
+ -- return (HieDiff f' s' d)
106
+ return (HieDiff f' " changed" d)
90
107
91
108
-- ---------------------------------------------------------------------
92
109
0 commit comments