From c86e70a3c9b80fb91e3404856ba287a7cf41d0aa Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Tue, 29 Sep 2020 20:41:28 +0300 Subject: [PATCH 1/4] Factor out formatting calls --- plugins/default/src/Ide/Plugin/Fourmolu.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/default/src/Ide/Plugin/Fourmolu.hs b/plugins/default/src/Ide/Plugin/Fourmolu.hs index 7f621d0153..741a991435 100644 --- a/plugins/default/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/default/src/Ide/Plugin/Fourmolu.hs @@ -74,10 +74,12 @@ provider lf ideState typ contents fp _ = withIndefiniteProgress lf title Cancell try @OrmoluException (ormolu conf fp' $ T.unpack cont) fp' = fromNormalizedFilePath fp + formatRegion region = ret <$> (fmt contents =<< mkConf fileOpts region) + case typ of - FormatText -> ret <$> (fmt contents =<< mkConf fileOpts fullRegion) + FormatText -> formatRegion fullRegion FormatRange (Range (Position sl _) (Position el _)) -> - ret <$> (fmt contents =<< mkConf fileOpts (rangeRegion sl el)) + formatRegion $ rangeRegion sl el where title = T.pack $ "Formatting " <> takeFileName (fromNormalizedFilePath fp) ret :: Either OrmoluException T.Text -> Either ResponseError (List TextEdit) From ba3c9cdab65e3ce6914e571562b5c3edcf87a94f Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Tue, 29 Sep 2020 20:44:40 +0300 Subject: [PATCH 2/4] Add a type signature for mkConf --- plugins/default/src/Ide/Plugin/Fourmolu.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/default/src/Ide/Plugin/Fourmolu.hs b/plugins/default/src/Ide/Plugin/Fourmolu.hs index 741a991435..e1cc17a382 100644 --- a/plugins/default/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/default/src/Ide/Plugin/Fourmolu.hs @@ -61,6 +61,8 @@ provider lf ideState typ contents fp _ = withIndefiniteProgress lf title Cancell let fullRegion = RegionIndices Nothing Nothing rangeRegion s e = RegionIndices (Just $ s + 1) (Just $ e + 1) + + mkConf :: [DynOption] -> region -> IO (Config region) mkConf o region = do printerOpts <- loadConfigFile True (Just fp') defaultPrinterOpts return $ defaultConfig @@ -69,6 +71,7 @@ provider lf ideState typ contents fp _ = withIndefiniteProgress lf title Cancell , cfgDebug = True , cfgPrinterOpts = printerOpts } + fmt :: T.Text -> Config RegionIndices -> IO (Either OrmoluException T.Text) fmt cont conf = try @OrmoluException (ormolu conf fp' $ T.unpack cont) From 1f7de576698efe87e5b02994dbba9b84229b95e2 Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Tue, 29 Sep 2020 21:29:22 +0300 Subject: [PATCH 3/4] Use latest fourmolu in stack.yamls --- stack-8.10.1.yaml | 3 ++- stack-8.10.2.yaml | 3 ++- stack-8.6.4.yaml | 3 ++- stack-8.6.5.yaml | 3 ++- stack-8.8.2.yaml | 3 ++- stack-8.8.3.yaml | 3 ++- stack-8.8.4.yaml | 3 ++- stack.yaml | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/stack-8.10.1.yaml b/stack-8.10.1.yaml index 1fe0cba806..2e1fdaf8fe 100644 --- a/stack-8.10.1.yaml +++ b/stack-8.10.1.yaml @@ -16,7 +16,8 @@ extra-deps: - clock-0.7.2 - data-tree-print-0.1.0.2 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb - HsYAML-aeson-0.2.0.0@rev:2 - monad-dijkstra-0.1.1.2 - opentelemetry-0.4.2 diff --git a/stack-8.10.2.yaml b/stack-8.10.2.yaml index ea835fd350..6f1b419db7 100644 --- a/stack-8.10.2.yaml +++ b/stack-8.10.2.yaml @@ -17,7 +17,8 @@ extra-deps: - clock-0.7.2 - data-tree-print-0.1.0.2 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb - HsYAML-aeson-0.2.0.0@rev:2 - monad-dijkstra-0.1.1.2 - opentelemetry-0.4.2 diff --git a/stack-8.6.4.yaml b/stack-8.6.4.yaml index edd214620a..150561e85a 100644 --- a/stack-8.6.4.yaml +++ b/stack-8.6.4.yaml @@ -21,7 +21,8 @@ extra-deps: - clock-0.7.2 - extra-1.7.3 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb - fuzzy-0.1.0.0 # - ghcide-0.1.0 - ghc-check-0.5.0.1 diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index 1092a77489..3753865492 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -20,7 +20,8 @@ extra-deps: - clock-0.7.2 - extra-1.7.3 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb - fuzzy-0.1.0.0 # - ghcide-0.1.0 - ghc-check-0.5.0.1 diff --git a/stack-8.8.2.yaml b/stack-8.8.2.yaml index 6c71cdfd59..aee3125197 100644 --- a/stack-8.8.2.yaml +++ b/stack-8.8.2.yaml @@ -19,7 +19,8 @@ extra-deps: - constrained-dynamic-0.1.0.0 - extra-1.7.3 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb # - ghcide-0.1.0 - ghc-check-0.5.0.1 - ghc-lib-parser-8.10.1.20200523 diff --git a/stack-8.8.3.yaml b/stack-8.8.3.yaml index c63e172e69..3c7b128c80 100644 --- a/stack-8.8.3.yaml +++ b/stack-8.8.3.yaml @@ -19,7 +19,8 @@ extra-deps: - constrained-dynamic-0.1.0.0 - extra-1.7.3 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb # - ghcide-0.1.0 - haskell-src-exts-1.21.1 - hlint-2.2.8 diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index 63fde601f3..bd5fc20b1c 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -21,7 +21,8 @@ extra-deps: - constrained-dynamic-0.1.0.0 - extra-1.7.3 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb # - ghcide-0.1.0 - haskell-src-exts-1.21.1 - hie-bios-0.7.1 diff --git a/stack.yaml b/stack.yaml index 1092a77489..3753865492 100644 --- a/stack.yaml +++ b/stack.yaml @@ -20,7 +20,8 @@ extra-deps: - clock-0.7.2 - extra-1.7.3 - floskell-0.10.4 -- fourmolu-0.1.0.0@rev:1 +- github: parsonsmatt/fourmolu + commit: 93ff2c108da8955fd6cf72d7cdc07696a72e9cfb - fuzzy-0.1.0.0 # - ghcide-0.1.0 - ghc-check-0.5.0.1 From b5fce53d4d866380d80cae4334087f0cc3231e1f Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Tue, 29 Sep 2020 21:29:30 +0300 Subject: [PATCH 4/4] Build with latest fourmolu --- plugins/default/src/Ide/Plugin/Fourmolu.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/default/src/Ide/Plugin/Fourmolu.hs b/plugins/default/src/Ide/Plugin/Fourmolu.hs index e1cc17a382..c7f8c9c430 100644 --- a/plugins/default/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/default/src/Ide/Plugin/Fourmolu.hs @@ -3,6 +3,7 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} +{-# LANGUAGE LambdaCase #-} module Ide.Plugin.Fourmolu ( @@ -13,6 +14,7 @@ where import Control.Exception import qualified Data.Text as T +import Data.Maybe (fromMaybe) import Development.IDE as D import qualified DynFlags as D import qualified EnumSet as S @@ -64,8 +66,19 @@ provider lf ideState typ contents fp _ = withIndefiniteProgress lf title Cancell mkConf :: [DynOption] -> region -> IO (Config region) mkConf o region = do - printerOpts <- loadConfigFile True (Just fp') defaultPrinterOpts - return $ defaultConfig + printerOpts <- do + filePrinterOpts <- + loadConfigFile fp' >>= \case + ConfigLoaded _ po -> pure $ Just po + _ -> pure Nothing + + pure $ + fillMissingPrinterOpts + (fromMaybe mempty filePrinterOpts) + defaultPrinterOpts + + + pure $ defaultConfig { cfgDynOptions = o , cfgRegion = region , cfgDebug = True