diff --git a/plugins/default/src/Ide/Plugin/Fourmolu.hs b/plugins/default/src/Ide/Plugin/Fourmolu.hs index 7f621d0153..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 @@ -61,23 +63,39 @@ 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 + 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 , cfgPrinterOpts = printerOpts } + fmt :: T.Text -> Config RegionIndices -> IO (Either OrmoluException T.Text) fmt cont conf = 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) 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