From f40d1c69899b40a861bd92fb950f668a8efc548c Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 8 Jun 2022 08:43:07 -0600 Subject: [PATCH 1/4] Add metadata to cabal file --- plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal index c814518989..75a8ab15ad 100644 --- a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal +++ b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal @@ -9,6 +9,8 @@ license: Apache-2.0 license-file: LICENSE author: The Haskell IDE Team copyright: The Haskell IDE Team +homepage: https://github.com/haskell/haskell-language-server +bug-reports: https://github.com/haskell/haskell-language-server/issues maintainer: alan.zimm@gmail.com category: Development build-type: Simple @@ -16,6 +18,10 @@ extra-source-files: LICENSE test/testdata/**/*.hs +source-repository head + type: git + location: git://github.com/haskell/haskell-language-server.git + library exposed-modules: Ide.Plugin.Fourmolu hs-source-dirs: src @@ -23,7 +29,7 @@ library build-depends: , base >=4.12 && <5 , filepath - , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 + , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 , ghc , ghc-boot-th , ghcide ^>=1.7 From c968e5427960714152622623cd93f856460ecf5e Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 8 Jun 2022 09:48:22 -0600 Subject: [PATCH 2/4] Support fourmolu 0.7 --- .../hls-fourmolu-plugin.cabal | 3 +- .../src/Ide/Plugin/Fourmolu.hs | 38 +++++++++++++++++-- stack.yaml | 1 + 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal index 75a8ab15ad..f242bcb1e9 100644 --- a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal +++ b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal @@ -29,7 +29,8 @@ library build-depends: , base >=4.12 && <5 , filepath - , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 + -- , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 + , fourmolu == 0.7.0.1 , ghc , ghc-boot-th , ghcide ^>=1.7 diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index ea19ddf8f5..cf8363a2e1 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -4,6 +4,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedLabels #-} +{-# LANGUAGE CPP #-} module Ide.Plugin.Fourmolu ( descriptor, @@ -34,6 +35,7 @@ import System.FilePath import System.IO (stderr) import System.Process.Run (proc, cwd) import System.Process.Text (readCreateProcessWithExitCode) +import Ormolu.Config descriptor :: PluginId -> PluginDescriptor IdeState descriptor plId = @@ -78,10 +80,17 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell ExitFailure n -> pure . Left . responseError $ "Fourmolu failed with exit code " <> T.pack (show n) else do - let format printerOpts = + let format fourmoluConfig = first (mkError . show) <$> try @OrmoluException (makeDiffTextEdit contents <$> ormolu config fp' (T.unpack contents)) where + printerOpts = +#if MIN_VERSION_fourmolu(0,7,0) + cfgFilePrinterOpts fourmoluConfig +#else + fourmoluConfig + +#endif config = defaultConfig { cfgDynOptions = map DynOption fileOpts @@ -91,6 +100,10 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell fillMissingPrinterOpts (printerOpts <> lspPrinterOpts) defaultPrinterOpts +#if MIN_VERSION_fourmolu(0,7,0) + , cfgFixityOverrides = + cfgFileFixities fourmoluConfig +#endif } in liftIO (loadConfigFile fp') >>= \case ConfigLoaded file opts -> liftIO $ do @@ -101,8 +114,19 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell . unlines $ ("No " ++ show configFileName ++ " found in any of:") : map (" " ++) searchDirs - format mempty - ConfigParseError f (_, err) -> do + format emptyOptions + where + emptyOptions = +#if MIN_VERSION_fourmolu(0,7,0) + FourmoluConfig + { cfgFilePrinterOpts = mempty + , cfgFileFixities = mempty + } +#else + mempty +#endif + + ConfigParseError f err -> do sendNotification SWindowShowMessage $ ShowMessageParams { _xtype = MtError @@ -110,7 +134,13 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell } return . Left $ responseError errorMessage where - errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack err + errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (convertErr err) + convertErr = +#if MIN_VERSION_fourmolu(0,7,0) + show +#else + snd +#endif where fp' = fromNormalizedFilePath fp title = "Formatting " <> T.pack (takeFileName fp') diff --git a/stack.yaml b/stack.yaml index b5b6d21530..9742f2f2b2 100644 --- a/stack.yaml +++ b/stack.yaml @@ -51,6 +51,7 @@ extra-deps: - rope-utf16-splay-0.3.2.0 - sqlite-simple-0.4.18.0@sha256:3ceea56375c0a3590c814e411a4eb86943f8d31b93b110ca159c90689b6b39e5,3002 - SVGFonts-1.7.0.1 # for Chart-diagrams, https://github.com/timbod7/haskell-chart/issues/232 +- fourmolu-0.7.0.1 # currently needed for ghcide>extra, etc. From abf85355a46650acf64147cf4bd245d5de39b078 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 8 Jun 2022 10:07:55 -0600 Subject: [PATCH 3/4] ok --- plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal index f242bcb1e9..75a8ab15ad 100644 --- a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal +++ b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal @@ -29,8 +29,7 @@ library build-depends: , base >=4.12 && <5 , filepath - -- , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 - , fourmolu == 0.7.0.1 + , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 , ghc , ghc-boot-th , ghcide ^>=1.7 From 1f14e7474dbb1b724e35c5394e4ffca66e24ff15 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 8 Jun 2022 10:10:08 -0600 Subject: [PATCH 4/4] stylish haskell --- .../hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs | 13 +++++++------ stack.yaml | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index cf8363a2e1..d981c3b09f 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -1,10 +1,10 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE DataKinds #-} {-# LANGUAGE DisambiguateRecordFields #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE OverloadedLabels #-} -{-# LANGUAGE CPP #-} module Ide.Plugin.Fourmolu ( descriptor, @@ -24,18 +24,19 @@ import Development.IDE.GHC.Compat as Compat hiding (Cpp) import qualified Development.IDE.GHC.Compat.Util as S import GHC.LanguageExtensions.Type (Extension (Cpp)) import Ide.Plugin.Properties -import Ide.PluginUtils (makeDiffTextEdit, usePropertyLsp) +import Ide.PluginUtils (makeDiffTextEdit, + usePropertyLsp) import Ide.Types import Language.LSP.Server hiding (defaultConfig) import Language.LSP.Types import Language.LSP.Types.Lens (HasTabSize (tabSize)) import Ormolu +import Ormolu.Config import System.Exit import System.FilePath import System.IO (stderr) -import System.Process.Run (proc, cwd) +import System.Process.Run (cwd, proc) import System.Process.Text (readCreateProcessWithExitCode) -import Ormolu.Config descriptor :: PluginId -> PluginDescriptor IdeState descriptor plId = diff --git a/stack.yaml b/stack.yaml index 9742f2f2b2..b5b6d21530 100644 --- a/stack.yaml +++ b/stack.yaml @@ -51,7 +51,6 @@ extra-deps: - rope-utf16-splay-0.3.2.0 - sqlite-simple-0.4.18.0@sha256:3ceea56375c0a3590c814e411a4eb86943f8d31b93b110ca159c90689b6b39e5,3002 - SVGFonts-1.7.0.1 # for Chart-diagrams, https://github.com/timbod7/haskell-chart/issues/232 -- fourmolu-0.7.0.1 # currently needed for ghcide>extra, etc.