From ed4e9fd725ce498aade0182a0fc89c61c323ac8a Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 29 Oct 2023 10:11:16 +0000 Subject: [PATCH 1/8] Remove redundant imports and extensions --- plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index 68fd1b2017..0e8fe0682d 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} -{-# LANGUAGE DisambiguateRecordFields #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedLabels #-} @@ -15,11 +14,11 @@ module Ide.Plugin.Fourmolu ( LogEvent, ) where -import Control.Exception (IOException, handle, try) +import Control.Exception (IOException, handle) import Control.Lens ((^.)) import Control.Monad (guard) import Control.Monad.Error.Class (MonadError (throwError)) -import Control.Monad.Trans.Except (ExceptT (..), mapExceptT, +import Control.Monad.Trans.Except (ExceptT (..), runExceptT) import Control.Monad.IO.Class (MonadIO (liftIO)) From 496acde5bd6cf68791e233efd04e1e996b1361f9 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 29 Oct 2023 21:20:05 +0000 Subject: [PATCH 2/8] Use `refineConfig` to load default fixities in Fourmolu --- plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index 0e8fe0682d..84118ce089 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -95,7 +95,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err) let config = - defaultConfig + refineConfig ModuleSource Nothing Nothing Nothing defaultConfig { cfgDynOptions = map DynOption fileOpts , cfgFixityOverrides = cfgFileFixities , cfgRegion = region From e03653731503fcc039b36437b1a322bb730db4f5 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 29 Oct 2023 21:54:15 +0000 Subject: [PATCH 3/8] Format --- .../src/Ide/Plugin/Fourmolu.hs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index 84118ce089..5791fe59cf 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -1,12 +1,12 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE OverloadedLabels #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedLabels #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeOperators #-} module Ide.Plugin.Fourmolu ( descriptor, @@ -18,9 +18,7 @@ import Control.Exception (IOException, handle) import Control.Lens ((^.)) import Control.Monad (guard) import Control.Monad.Error.Class (MonadError (throwError)) -import Control.Monad.Trans.Except (ExceptT (..), - runExceptT) - +import Control.Monad.Trans.Except (ExceptT (..), runExceptT) import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.Trans.Class (MonadTrans (lift)) import Data.Bifunctor (bimap) From 7124b9d377fd906ce857537ba70c980df68ae98e Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 29 Oct 2023 21:54:29 +0000 Subject: [PATCH 4/8] Fix GHC 9.2 --- plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index 5791fe59cf..8fcde79282 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -14,7 +14,7 @@ module Ide.Plugin.Fourmolu ( LogEvent, ) where -import Control.Exception (IOException, handle) +import Control.Exception import Control.Lens ((^.)) import Control.Monad (guard) import Control.Monad.Error.Class (MonadError (throwError)) From a603bd3e2b042ab8da96a70288d11155294bd3a9 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 29 Oct 2023 22:13:54 +0000 Subject: [PATCH 5/8] Format --- plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index 8fcde79282..dad2e21814 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -18,9 +18,9 @@ import Control.Exception import Control.Lens ((^.)) import Control.Monad (guard) import Control.Monad.Error.Class (MonadError (throwError)) -import Control.Monad.Trans.Except (ExceptT (..), runExceptT) import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.Trans.Class (MonadTrans (lift)) +import Control.Monad.Trans.Except (ExceptT (..), runExceptT) import Data.Bifunctor (bimap) import Data.List (intercalate) import Data.Maybe (catMaybes) From a2c339afddfb1032d608af464fa0384d2ff9e679 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sun, 29 Oct 2023 22:19:13 +0000 Subject: [PATCH 6/8] Fix build on old Fourmolu versions --- plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index dad2e21814..c125c5e957 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -93,7 +93,10 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err) let config = - refineConfig ModuleSource Nothing Nothing Nothing defaultConfig +#if MIN_VERSION_fourmolu(0,13,0) + refineConfig ModuleSource Nothing Nothing Nothing +#endif + defaultConfig { cfgDynOptions = map DynOption fileOpts , cfgFixityOverrides = cfgFileFixities , cfgRegion = region From 71cc7b019aeee91cb5e7dfb37f64cfcd7e7205da Mon Sep 17 00:00:00 2001 From: George Thomas Date: Mon, 30 Oct 2023 23:57:35 +0000 Subject: [PATCH 7/8] Avoid pattern match warning --- plugins/hls-fourmolu-plugin/test/Main.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/test/Main.hs b/plugins/hls-fourmolu-plugin/test/Main.hs index 875720c826..1e6ab5eaea 100644 --- a/plugins/hls-fourmolu-plugin/test/Main.hs +++ b/plugins/hls-fourmolu-plugin/test/Main.hs @@ -4,6 +4,7 @@ module Main ) where import Data.Aeson +import qualified Data.Aeson.KeyMap as KM import Data.Functor import Ide.Plugin.Config import qualified Ide.Plugin.Fourmolu as Fourmolu @@ -33,7 +34,7 @@ tests = goldenWithFourmolu :: Bool -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree goldenWithFourmolu cli title path desc = goldenWithHaskellDocFormatter def fourmoluPlugin "fourmolu" conf title testDataDir path desc "hs" where - conf = def{plcConfig = (\(Object obj) -> obj) $ object ["external" .= cli]} + conf = def{plcConfig = KM.fromList ["external" .= cli]} testDataDir :: FilePath testDataDir = "test" "testdata" From 1c55cb4a478b2920c727652aeda238e80ae9fb54 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Tue, 31 Oct 2023 00:09:35 +0000 Subject: [PATCH 8/8] Add regression test for Fourmolu fixities --- plugins/hls-fourmolu-plugin/test/Main.hs | 2 ++ .../test/testdata/Fourmolu3.formatted.hs | 7 +++++++ plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.hs | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.formatted.hs create mode 100644 plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.hs diff --git a/plugins/hls-fourmolu-plugin/test/Main.hs b/plugins/hls-fourmolu-plugin/test/Main.hs index 1e6ab5eaea..36d462b833 100644 --- a/plugins/hls-fourmolu-plugin/test/Main.hs +++ b/plugins/hls-fourmolu-plugin/test/Main.hs @@ -29,6 +29,8 @@ tests = formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) , goldenWithFourmolu cli "formats imports correctly" "Fourmolu2" "formatted" $ \doc -> do formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) + , goldenWithFourmolu cli "uses correct operator fixities" "Fourmolu3" "formatted" $ \doc -> do + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) ] goldenWithFourmolu :: Bool -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.formatted.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.formatted.hs new file mode 100644 index 0000000000..ca766959cc --- /dev/null +++ b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.formatted.hs @@ -0,0 +1,7 @@ +b :: Bool +b = + id $ + id $ + case True && True of + True -> True + False -> False diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.hs new file mode 100644 index 0000000000..fafe4da859 --- /dev/null +++ b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu3.hs @@ -0,0 +1,6 @@ +b :: Bool +b = + id $ id $ + case True && True of + True -> True + False -> False