Skip to content

Commit 166b387

Browse files
committed
Use the file contents from the LSP request
1 parent e4234a3 commit 166b387

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

plugins/hls-cabal-fmt-plugin/hls-cabal-fmt-plugin.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ library
3838
, lens
3939
, lsp-types
4040
, mtl
41-
, process
41+
, process-extras
4242
, text
4343
, transformers
4444

plugins/hls-cabal-fmt-plugin/src/Ide/Plugin/CabalFmt.hs

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,29 @@ import Development.IDE hiding (pluginHandlers)
1111
import Ide.Plugin.Error (PluginError (PluginInternalError, PluginInvalidParams))
1212
import Ide.PluginUtils
1313
import Ide.Types
14-
import Language.LSP.Protocol.Lens as L
14+
import qualified Language.LSP.Protocol.Lens as L
1515
import Language.LSP.Protocol.Types
1616
import Prelude hiding (log)
1717
import System.Directory
1818
import System.Exit
1919
import System.FilePath
20-
import System.Process
20+
import System.Process.ListLike
21+
import qualified System.Process.Text as Process
2122

2223
data Log
2324
= LogProcessInvocationFailure Int
24-
| LogReadCreateProcessInfo String [String]
25+
| LogReadCreateProcessInfo T.Text [String]
2526
| LogInvalidInvocationInfo
2627
| LogCabalFmtNotFound
2728
deriving (Show)
2829

2930
instance 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."
5253
provider 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

plugins/hls-cabal-fmt-plugin/test/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tests found = testGroup "cabal-fmt"
3939
cabalFmtGolden found "formats a simple document" "simple_testdata" "formatted_document" $ \doc -> do
4040
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
4141

42-
, knownBrokenOnWindows "expand:src comment bug in cabal-fmt on windows" $
42+
, expectFailBecause "cabal-fmt can't expand modules if .cabal file is read from stdin. Tracking issue: https://github.com/phadej/cabal-fmt/pull/82" $
4343
cabalFmtGolden found "formats a document with expand:src comment" "commented_testdata" "formatted_document" $ \doc -> do
4444
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
4545

0 commit comments

Comments
 (0)