|
2 | 2 | {-# LANGUAGE DataKinds #-}
|
3 | 3 | {-# LANGUAGE DisambiguateRecordFields #-}
|
4 | 4 | {-# LANGUAGE LambdaCase #-}
|
| 5 | +{-# LANGUAGE NamedFieldPuns #-} |
5 | 6 | {-# LANGUAGE OverloadedLabels #-}
|
6 | 7 | {-# LANGUAGE OverloadedStrings #-}
|
7 | 8 | {-# LANGUAGE TypeApplications #-}
|
@@ -63,10 +64,26 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell
|
63 | 64 | . fmap (join . first (mkError . show))
|
64 | 65 | . try @IOException
|
65 | 66 | $ 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 |
67 | 83 | readCreateProcessWithExitCode
|
68 | 84 | ( proc "fourmolu" $
|
69 | 85 | ["-d"]
|
| 86 | + <> mwhen noCabal ["--no-cabal"] |
70 | 87 | <> catMaybes
|
71 | 88 | [ ("--start-line=" <>) . show <$> regionStartLine region
|
72 | 89 | , ("--end-line=" <>) . show <$> regionEndLine region
|
@@ -163,3 +180,10 @@ convertDynFlags df =
|
163 | 180 | Cpp -> "-XCPP"
|
164 | 181 | x -> "-X" ++ show x
|
165 | 182 | 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