Skip to content

Use latest fourmolu #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions plugins/default/src/Ide/Plugin/Fourmolu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE LambdaCase #-}

module Ide.Plugin.Fourmolu
(
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion stack-8.10.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack-8.10.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack-8.6.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack-8.6.5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack-8.8.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack-8.8.3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack-8.8.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down