@@ -11,28 +11,29 @@ import Development.IDE hiding (pluginHandlers)
1111import Ide.Plugin.Error (PluginError (PluginInternalError , PluginInvalidParams ))
1212import Ide.PluginUtils
1313import Ide.Types
14- import Language.LSP.Protocol.Lens as L
14+ import qualified Language.LSP.Protocol.Lens as L
1515import Language.LSP.Protocol.Types
1616import Prelude hiding (log )
1717import System.Directory
1818import System.Exit
1919import System.FilePath
20- import System.Process
20+ import System.Process.ListLike
21+ import qualified System.Process.Text as Process
2122
2223data Log
2324 = LogProcessInvocationFailure Int
24- | LogReadCreateProcessInfo String [String ]
25+ | LogReadCreateProcessInfo T. Text [String ]
2526 | LogInvalidInvocationInfo
2627 | LogCabalFmtNotFound
2728 deriving (Show )
2829
2930instance Pretty Log where
3031 pretty = \ case
31- LogProcessInvocationFailure code -> " Invocation of cabal-fmt failed with code" <+> pretty code
32+ LogProcessInvocationFailure exitCode -> " Invocation of cabal-fmt failed with code" <+> pretty exitCode
3233 LogReadCreateProcessInfo stdErrorOut args ->
3334 vcat $
3435 [" Invocation of cabal-fmt with arguments" <+> pretty args]
35- ++ [" failed with standard error:" <+> pretty stdErrorOut | not (null stdErrorOut)]
36+ ++ [" failed with standard error:" <+> pretty stdErrorOut | not (T. null stdErrorOut)]
3637 LogInvalidInvocationInfo -> " Invocation of cabal-fmt with range was called but is not supported."
3738 LogCabalFmtNotFound -> " Couldn't find executable 'cabal-fmt'"
3839
@@ -50,24 +51,24 @@ provider recorder _ (FormatRange _) _ _ _ = do
5051 logWith recorder Info LogInvalidInvocationInfo
5152 throwError $ PluginInvalidParams " You cannot format a text-range using cabal-fmt."
5253provider recorder _ide FormatText contents nfp opts = do
53- let cabalFmtArgs = [fp, " --indent" , show tabularSize]
54+ let cabalFmtArgs = [ " --indent" , show tabularSize]
5455 x <- liftIO $ findExecutable " cabal-fmt"
5556 case x of
5657 Just _ -> do
5758 (exitCode, out, err) <-
58- liftIO $ readCreateProcessWithExitCode
59+ liftIO $ Process. readCreateProcessWithExitCode
5960 ( proc " cabal-fmt" cabalFmtArgs
6061 )
6162 { cwd = Just $ takeDirectory fp
6263 }
63- " "
64+ contents
6465 log Debug $ LogReadCreateProcessInfo err cabalFmtArgs
6566 case exitCode of
6667 ExitFailure code -> do
6768 log Error $ LogProcessInvocationFailure code
6869 throwError (PluginInternalError " Failed to invoke cabal-fmt" )
6970 ExitSuccess -> do
70- let fmtDiff = makeDiffTextEdit contents ( T. pack out)
71+ let fmtDiff = makeDiffTextEdit contents out
7172 pure $ InL fmtDiff
7273 Nothing -> do
7374 log Error LogCabalFmtNotFound
0 commit comments