Skip to content

Commit 581686c

Browse files
committed
Only use Fourmolu --no-cabal flag on recent versions
1 parent 0bbc545 commit 581686c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
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" $
69-
["-d", "--no-cabal"]
85+
["-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)