Skip to content

Commit e6ac381

Browse files
Add support for Fourmolu 0.14.0.0 (#3796)
* Remove unneeded support for GHC 8.10 * Add support for Fourmolu 0.14.0.0 * Break out format call * Inline format call * mapExceptT liftIO . ExceptT => ExceptT . liftIO
1 parent bada830 commit e6ac381

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ package *
5252

5353
write-ghc-environment-files: never
5454

55-
index-state: 2023-08-25T00:00:00Z
55+
index-state: 2023-09-08T00:00:00Z
5656

5757
constraints:
5858
-- For GHC 9.4, older versions of entropy fail to build on Windows

plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ library
4242
, text
4343
, transformers
4444

45-
if impl(ghc >= 8.10) && impl(ghc < 9.0)
46-
build-depends: fourmolu ^>= 0.9
47-
elif impl(ghc >= 9.0) && impl(ghc < 9.2)
45+
if impl(ghc >= 9.0) && impl(ghc < 9.2)
4846
build-depends: fourmolu ^>= 0.11
4947
elif impl(ghc >= 9.2) && impl(ghc < 9.8)
50-
build-depends: fourmolu ^>= 0.13
48+
build-depends: fourmolu ^>= 0.14
5149
else
5250
buildable: false
5351

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE NamedFieldPuns #-}
66
{-# LANGUAGE OverloadedLabels #-}
77
{-# LANGUAGE OverloadedStrings #-}
8+
{-# LANGUAGE RecordWildCards #-}
89
{-# LANGUAGE TypeApplications #-}
910
{-# LANGUAGE TypeOperators #-}
1011

@@ -71,39 +72,19 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
7172
<$> liftIO (runAction "Fourmolu" ideState $ use GhcSession fp)
7273
useCLI <- liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #external plId properties
7374
if useCLI
74-
then mapExceptT liftIO $ ExceptT
75-
$ handle @IOException
76-
(pure . Left . PluginInternalError . T.pack . show)
77-
$ runExceptT $ cliHandler fileOpts
75+
then ExceptT . liftIO $
76+
handle @IOException (pure . Left . PluginInternalError . T.pack . show) $
77+
runExceptT (cliHandler fileOpts)
7878
else do
7979
logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu
80-
let format fourmoluConfig = ExceptT $
81-
bimap (PluginInternalError . T.pack . show) (InL . makeDiffTextEdit contents)
82-
#if MIN_VERSION_fourmolu(0,11,0)
83-
<$> try @OrmoluException (ormolu config fp' contents)
84-
#else
85-
<$> try @OrmoluException (ormolu config fp' (T.unpack contents))
86-
#endif
87-
where
88-
printerOpts = cfgFilePrinterOpts fourmoluConfig
89-
config =
90-
defaultConfig
91-
{ cfgDynOptions = map DynOption fileOpts
92-
, cfgFixityOverrides = cfgFileFixities fourmoluConfig
93-
, cfgRegion = region
94-
, cfgDebug = False
95-
, cfgPrinterOpts =
96-
fillMissingPrinterOpts
97-
(printerOpts <> lspPrinterOpts)
98-
defaultPrinterOpts
99-
}
100-
in liftIO (loadConfigFile fp') >>= \case
80+
FourmoluConfig{..} <-
81+
liftIO (loadConfigFile fp') >>= \case
10182
ConfigLoaded file opts -> do
10283
logWith recorder Info $ ConfigPath file
103-
mapExceptT liftIO $ format opts
84+
pure opts
10485
ConfigNotFound searchDirs -> do
10586
logWith recorder Info $ NoConfigPath searchDirs
106-
mapExceptT liftIO $ format emptyConfig
87+
pure emptyConfig
10788
ConfigParseError f err -> do
10889
lift $ sendNotification SMethod_WindowShowMessage $
10990
ShowMessageParams
@@ -113,6 +94,18 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
11394
throwError $ PluginInternalError errorMessage
11495
where
11596
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)
97+
98+
let config =
99+
defaultConfig
100+
{ cfgDynOptions = map DynOption fileOpts
101+
, cfgFixityOverrides = cfgFileFixities
102+
, cfgRegion = region
103+
, cfgDebug = False
104+
, cfgPrinterOpts = resolvePrinterOpts [lspPrinterOpts, cfgFilePrinterOpts]
105+
}
106+
ExceptT . liftIO $
107+
bimap (PluginInternalError . T.pack . show) (InL . makeDiffTextEdit contents)
108+
<$> try @OrmoluException (ormolu config fp' contents)
116109
where
117110
fp' = fromNormalizedFilePath fp
118111
title = "Formatting " <> T.pack (takeFileName fp')
@@ -200,3 +193,8 @@ newtype CLIVersionInfo = CLIVersionInfo
200193

201194
mwhen :: Monoid a => Bool -> a -> a
202195
mwhen b x = if b then x else mempty
196+
197+
#if !MIN_VERSION_fourmolu(0,14,0)
198+
resolvePrinterOpts :: [PrinterOptsPartial] -> PrinterOptsTotal
199+
resolvePrinterOpts = foldr fillMissingPrinterOpts defaultPrinterOpts
200+
#endif

0 commit comments

Comments
 (0)