@@ -30,8 +30,8 @@ applyRefactDescriptor = PluginDescriptor
3030 buildCommand applyOneCmd " applyOne" " Apply a single hint"
3131 [" .hs" ] [CtxPoint ] []
3232
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 ] []
3535
3636 ]
3737 , pdExposedServices = []
@@ -45,39 +45,55 @@ applyOneCmd = CmdSync $ \_ctxs req -> do
4545 case getParams (IdFile " file" :& IdPos " start_pos" :& RNil ) req of
4646 Left err -> return err
4747 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)
4949 case res of
5050 Left err -> return $ IdeResponseFail (IdeError PluginError
5151 (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)
5553 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 )
5755
5856
5957-- ---------------------------------------------------------------------
6058
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
6377 withTempFile $ \ f -> do
64- absFile <- makeAbsolute file
78+ -- absFile <- makeAbsolute file
6579 -- hlint /tmp/Foo.hs --refactor --refactor-options="-o /tmp/Bar.hs --pos 2,8"
6680
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 ]
7287 logm $ " applyHint=" ++ show hlintOpts
7388 res <- catchException $ hlint hlintOpts
7489 logm $ " applyHint:res=" ++ show res
7590 case res of
76- Left ExitSuccess -> do
91+ Left " ExitSuccess" -> do
7792 diff <- makeDiffResult file f
7893 logm $ " applyHint:diff=" ++ show diff
7994 return $ Right diff
80- _ -> return res
95+ Left x -> return $ Left (show x)
96+ Right x -> return $ Left (show x)
8197
8298-- ---------------------------------------------------------------------
8399
@@ -86,7 +102,8 @@ makeDiffResult orig new = do
86102 (HieDiff f s d) <- diffFiles orig new
87103 f' <- liftIO $ makeRelativeToCurrentDirectory f
88104 s' <- liftIO $ makeRelativeToCurrentDirectory s
89- return (HieDiff f' s' d)
105+ -- return (HieDiff f' s' d)
106+ return (HieDiff f' " changed" d)
90107
91108-- ---------------------------------------------------------------------
92109
0 commit comments