@@ -11,28 +11,29 @@ import Development.IDE hiding (pluginHandlers)
11
11
import Ide.Plugin.Error (PluginError (PluginInternalError , PluginInvalidParams ))
12
12
import Ide.PluginUtils
13
13
import Ide.Types
14
- import Language.LSP.Protocol.Lens as L
14
+ import qualified Language.LSP.Protocol.Lens as L
15
15
import Language.LSP.Protocol.Types
16
16
import Prelude hiding (log )
17
17
import System.Directory
18
18
import System.Exit
19
19
import System.FilePath
20
- import System.Process
20
+ import System.Process.ListLike
21
+ import qualified System.Process.Text as Process
21
22
22
23
data Log
23
24
= LogProcessInvocationFailure Int
24
- | LogReadCreateProcessInfo String [String ]
25
+ | LogReadCreateProcessInfo T. Text [String ]
25
26
| LogInvalidInvocationInfo
26
27
| LogCabalFmtNotFound
27
28
deriving (Show )
28
29
29
30
instance Pretty Log where
30
31
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
32
33
LogReadCreateProcessInfo stdErrorOut args ->
33
34
vcat $
34
35
[" 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)]
36
37
LogInvalidInvocationInfo -> " Invocation of cabal-fmt with range was called but is not supported."
37
38
LogCabalFmtNotFound -> " Couldn't find executable 'cabal-fmt'"
38
39
@@ -50,24 +51,24 @@ provider recorder _ (FormatRange _) _ _ _ = do
50
51
logWith recorder Info LogInvalidInvocationInfo
51
52
throwError $ PluginInvalidParams " You cannot format a text-range using cabal-fmt."
52
53
provider recorder _ide FormatText contents nfp opts = do
53
- let cabalFmtArgs = [fp, " --indent" , show tabularSize]
54
+ let cabalFmtArgs = [ " --indent" , show tabularSize]
54
55
x <- liftIO $ findExecutable " cabal-fmt"
55
56
case x of
56
57
Just _ -> do
57
58
(exitCode, out, err) <-
58
- liftIO $ readCreateProcessWithExitCode
59
+ liftIO $ Process. readCreateProcessWithExitCode
59
60
( proc " cabal-fmt" cabalFmtArgs
60
61
)
61
62
{ cwd = Just $ takeDirectory fp
62
63
}
63
- " "
64
+ contents
64
65
log Debug $ LogReadCreateProcessInfo err cabalFmtArgs
65
66
case exitCode of
66
67
ExitFailure code -> do
67
68
log Error $ LogProcessInvocationFailure code
68
69
throwError (PluginInternalError " Failed to invoke cabal-fmt" )
69
70
ExitSuccess -> do
70
- let fmtDiff = makeDiffTextEdit contents ( T. pack out)
71
+ let fmtDiff = makeDiffTextEdit contents out
71
72
pure $ InL fmtDiff
72
73
Nothing -> do
73
74
log Error LogCabalFmtNotFound
0 commit comments