Skip to content

Commit 8a5840a

Browse files
authored
Merge pull request #2950 from haskell/fourmolu-0.7-fixes
Fix Fourmolu 0.7 support
2 parents bb6b4e1 + 581686c commit 8a5840a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Diff for: cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ package *
4444

4545
write-ghc-environment-files: never
4646

47-
index-state: 2022-04-30T21:02:45Z
47+
index-state: 2022-06-12T00:00:00Z
4848

4949
constraints:
5050
hyphenation +embed,

Diff for: plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE DataKinds #-}
33
{-# LANGUAGE DisambiguateRecordFields #-}
44
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE NamedFieldPuns #-}
56
{-# LANGUAGE OverloadedLabels #-}
67
{-# LANGUAGE OverloadedStrings #-}
78
{-# LANGUAGE TypeApplications #-}
@@ -63,10 +64,26 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell
6364
. fmap (join . first (mkError . show))
6465
. try @IOException
6566
$ do
66-
(exitCode, out, err) <-
67+
CLIVersionInfo{noCabal} <- do -- check Fourmolu version so that we know which flags to use
68+
(exitCode, out, _err) <- readCreateProcessWithExitCode ( proc "fourmolu" ["-v"] ) ""
69+
let version = do
70+
guard $ exitCode == ExitSuccess
71+
"fourmolu" : v : _ <- pure $ T.words out
72+
pure $ T.splitOn "." v
73+
case version of
74+
Just v -> pure CLIVersionInfo
75+
{ noCabal = v >= ["0", "7"]
76+
}
77+
Nothing -> do
78+
T.hPutStrLn stderr "couldn't get Fourmolu version"
79+
pure CLIVersionInfo
80+
{ noCabal = True
81+
}
82+
(exitCode, out, err) <- -- run Fourmolu
6783
readCreateProcessWithExitCode
6884
( proc "fourmolu" $
6985
["-d"]
86+
<> mwhen noCabal ["--no-cabal"]
7087
<> catMaybes
7188
[ ("--start-line=" <>) . show <$> regionStartLine region
7289
, ("--end-line=" <>) . show <$> regionEndLine region
@@ -163,3 +180,10 @@ convertDynFlags df =
163180
Cpp -> "-XCPP"
164181
x -> "-X" ++ show x
165182
in pp <> pm <> ex
183+
184+
newtype CLIVersionInfo = CLIVersionInfo
185+
{ noCabal :: Bool
186+
}
187+
188+
mwhen :: Monoid a => Bool -> a -> a
189+
mwhen b x = if b then x else mempty

0 commit comments

Comments
 (0)