Skip to content

Commit f2c6b02

Browse files
authored
Merge pull request #3855 from haskell/fourmolu-default-fixities
Load default operator fixities in Fourmolu plugin non-CLI mode
2 parents 5bf1b75 + 1c55cb4 commit f2c6b02

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DataKinds #-}
3-
{-# LANGUAGE DisambiguateRecordFields #-}
4-
{-# LANGUAGE LambdaCase #-}
5-
{-# LANGUAGE NamedFieldPuns #-}
6-
{-# LANGUAGE OverloadedLabels #-}
7-
{-# LANGUAGE OverloadedStrings #-}
8-
{-# LANGUAGE RecordWildCards #-}
9-
{-# LANGUAGE TypeApplications #-}
10-
{-# LANGUAGE TypeOperators #-}
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE LambdaCase #-}
4+
{-# LANGUAGE NamedFieldPuns #-}
5+
{-# LANGUAGE OverloadedLabels #-}
6+
{-# LANGUAGE OverloadedStrings #-}
7+
{-# LANGUAGE RecordWildCards #-}
8+
{-# LANGUAGE TypeApplications #-}
9+
{-# LANGUAGE TypeOperators #-}
1110

1211
module Ide.Plugin.Fourmolu (
1312
descriptor,
1413
provider,
1514
LogEvent,
1615
) where
1716

18-
import Control.Exception (IOException, handle, try)
17+
import Control.Exception
1918
import Control.Lens ((^.))
2019
import Control.Monad (guard)
2120
import Control.Monad.Error.Class (MonadError (throwError))
22-
import Control.Monad.Trans.Except (ExceptT (..), mapExceptT,
23-
runExceptT)
24-
2521
import Control.Monad.IO.Class (MonadIO (liftIO))
2622
import Control.Monad.Trans.Class (MonadTrans (lift))
23+
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
2724
import Data.Bifunctor (bimap)
2825
import Data.List (intercalate)
2926
import Data.Maybe (catMaybes)
@@ -96,6 +93,9 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
9693
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)
9794

9895
let config =
96+
#if MIN_VERSION_fourmolu(0,13,0)
97+
refineConfig ModuleSource Nothing Nothing Nothing
98+
#endif
9999
defaultConfig
100100
{ cfgDynOptions = map DynOption fileOpts
101101
, cfgFixityOverrides = cfgFileFixities

plugins/hls-fourmolu-plugin/test/Main.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Main
44
) where
55

66
import Data.Aeson
7+
import qualified Data.Aeson.KeyMap as KM
78
import Data.Functor
89
import Ide.Plugin.Config
910
import qualified Ide.Plugin.Fourmolu as Fourmolu
@@ -28,12 +29,14 @@ tests =
2829
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
2930
, goldenWithFourmolu cli "formats imports correctly" "Fourmolu2" "formatted" $ \doc -> do
3031
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
32+
, goldenWithFourmolu cli "uses correct operator fixities" "Fourmolu3" "formatted" $ \doc -> do
33+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
3134
]
3235

3336
goldenWithFourmolu :: Bool -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
3437
goldenWithFourmolu cli title path desc = goldenWithHaskellDocFormatter def fourmoluPlugin "fourmolu" conf title testDataDir path desc "hs"
3538
where
36-
conf = def{plcConfig = (\(Object obj) -> obj) $ object ["external" .= cli]}
39+
conf = def{plcConfig = KM.fromList ["external" .= cli]}
3740

3841
testDataDir :: FilePath
3942
testDataDir = "test" </> "testdata"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
b :: Bool
2+
b =
3+
id $
4+
id $
5+
case True && True of
6+
True -> True
7+
False -> False
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
b :: Bool
2+
b =
3+
id $ id $
4+
case True && True of
5+
True -> True
6+
False -> False

0 commit comments

Comments
 (0)