hls-fourmolu-plugin 2.2.0.0 → 2.3.0.0
raw patch · 3 files changed
+39/−111 lines, 3 filesdep ~basedep ~fourmoludep ~ghcidePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, fourmolu, ghcide, hls-plugin-api, hls-test-utils
API changes (from Hackage documentation)
- Ide.Plugin.Fourmolu.Shim: addFixityOverrides :: FixityOverrides -> Config region -> Config region
- Ide.Plugin.Fourmolu.Shim: cfgFileFixities :: FourmoluConfig -> FixityMap
- Ide.Plugin.Fourmolu.Shim: cfgFilePrinterOpts :: FourmoluConfig -> PrinterOptsPartial
- Ide.Plugin.Fourmolu.Shim: emptyConfig :: FourmoluConfig
- Ide.Plugin.Fourmolu.Shim: showParseError :: Show parseException => parseException -> String
Files
- hls-fourmolu-plugin.cabal +12/−7
- src/Ide/Plugin/Fourmolu.hs +27/−29
- src/Ide/Plugin/Fourmolu/Shim.hs +0/−75
hls-fourmolu-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: hls-fourmolu-plugin-version: 2.2.0.0+version: 2.3.0.0 synopsis: Integration with the Fourmolu code formatter description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -26,17 +26,15 @@ buildable: True exposed-modules: Ide.Plugin.Fourmolu- , Ide.Plugin.Fourmolu.Shim hs-source-dirs: src ghc-options: -Wall build-depends: , base >=4.12 && <5 , filepath- , fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11 || ^>= 0.12 || ^>= 0.13 , ghc , ghc-boot-th- , ghcide == 2.2.0.0- , hls-plugin-api == 2.2.0.0+ , ghcide == 2.3.0.0+ , hls-plugin-api == 2.3.0.0 , lens , lsp , mtl@@ -44,6 +42,13 @@ , text , transformers + if impl(ghc >= 9.0) && impl(ghc < 9.2)+ build-depends: fourmolu ^>= 0.11+ elif impl(ghc >= 9.2) && impl(ghc < 9.8)+ build-depends: fourmolu ^>= 0.14+ else+ buildable: False+ -- fourmolu 0.9.0 fails to build on Windows CI for reasons unknown if impl(ghc >= 9.2) && os(windows) && impl(ghc < 9.4) build-depends: fourmolu > 0.9.0.0 || < 0.9.0.0@@ -59,11 +64,11 @@ build-tool-depends: fourmolu:fourmolu build-depends:- , base+ , base >=4.12 && <5 , aeson , containers , filepath , hls-fourmolu-plugin , hls-plugin-api- , hls-test-utils == 2.2.0.0+ , hls-test-utils == 2.3.0.0 , lsp-test
src/Ide/Plugin/Fourmolu.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} @@ -34,7 +35,6 @@ import qualified Development.IDE.GHC.Compat.Util as S import GHC.LanguageExtensions.Type (Extension (Cpp)) import Ide.Plugin.Error-import Ide.Plugin.Fourmolu.Shim import Ide.Plugin.Properties import Ide.PluginUtils (makeDiffTextEdit) import Ide.Types@@ -43,6 +43,7 @@ import Language.LSP.Protocol.Types import Language.LSP.Server hiding (defaultConfig) import Ormolu+import Ormolu.Config import System.Exit import System.FilePath import System.Process.Run (cwd, proc)@@ -71,39 +72,19 @@ <$> liftIO (runAction "Fourmolu" ideState $ use GhcSession fp) useCLI <- liftIO $ runAction "Fourmolu" ideState $ usePropertyAction #external plId properties if useCLI- then mapExceptT liftIO $ ExceptT- $ handle @IOException- (pure . Left . PluginInternalError . T.pack . show)- $ runExceptT $ cliHandler fileOpts+ then ExceptT . liftIO $+ handle @IOException (pure . Left . PluginInternalError . T.pack . show) $+ runExceptT (cliHandler fileOpts) else do logWith recorder Debug $ LogCompiledInVersion VERSION_fourmolu- let format fourmoluConfig = ExceptT $- bimap (PluginInternalError . T.pack . show) (InL . makeDiffTextEdit contents)-#if MIN_VERSION_fourmolu(0,11,0)- <$> try @OrmoluException (ormolu config fp' contents)-#else- <$> try @OrmoluException (ormolu config fp' (T.unpack contents))-#endif- where- printerOpts = cfgFilePrinterOpts fourmoluConfig- config =- addFixityOverrides (cfgFileFixities fourmoluConfig) $- defaultConfig- { cfgDynOptions = map DynOption fileOpts- , cfgRegion = region- , cfgDebug = False- , cfgPrinterOpts =- fillMissingPrinterOpts- (printerOpts <> lspPrinterOpts)- defaultPrinterOpts- }- in liftIO (loadConfigFile fp') >>= \case+ FourmoluConfig{..} <-+ liftIO (loadConfigFile fp') >>= \case ConfigLoaded file opts -> do logWith recorder Info $ ConfigPath file- mapExceptT liftIO $ format opts+ pure opts ConfigNotFound searchDirs -> do logWith recorder Info $ NoConfigPath searchDirs- mapExceptT liftIO $ format emptyConfig+ pure emptyConfig ConfigParseError f err -> do lift $ sendNotification SMethod_WindowShowMessage $ ShowMessageParams@@ -112,7 +93,19 @@ } throwError $ PluginInternalError errorMessage where- errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (showParseError err)+ errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)++ let config =+ defaultConfig+ { cfgDynOptions = map DynOption fileOpts+ , cfgFixityOverrides = cfgFileFixities+ , cfgRegion = region+ , cfgDebug = False+ , cfgPrinterOpts = resolvePrinterOpts [lspPrinterOpts, cfgFilePrinterOpts]+ }+ ExceptT . liftIO $+ bimap (PluginInternalError . T.pack . show) (InL . makeDiffTextEdit contents)+ <$> try @OrmoluException (ormolu config fp' contents) where fp' = fromNormalizedFilePath fp title = "Formatting " <> T.pack (takeFileName fp')@@ -200,3 +193,8 @@ mwhen :: Monoid a => Bool -> a -> a mwhen b x = if b then x else mempty++#if !MIN_VERSION_fourmolu(0,14,0)+resolvePrinterOpts :: [PrinterOptsPartial] -> PrinterOptsTotal+resolvePrinterOpts = foldr fillMissingPrinterOpts defaultPrinterOpts+#endif
− src/Ide/Plugin/Fourmolu/Shim.hs
@@ -1,75 +0,0 @@-{-# LANGUAGE CPP #-}--module Ide.Plugin.Fourmolu.Shim (- -- * FourmoluConfig- cfgFilePrinterOpts,- cfgFileFixities,- emptyConfig,-- -- * FixityMap- addFixityOverrides,-- -- * ConfigParseError- showParseError,-) where--import Ormolu.Config--#if MIN_VERSION_fourmolu(0,7,0)-import Ormolu.Fixity-#endif--{-- Backport FourmoluConfig --}--#if MIN_VERSION_fourmolu(0,7,0)--- these functions are now defined-#else-type FourmoluConfig = PrinterOptsPartial--cfgFilePrinterOpts :: FourmoluConfig -> PrinterOptsPartial-cfgFilePrinterOpts = id--cfgFileFixities :: FourmoluConfig -> FixityOverrides-cfgFileFixities _ = mempty-#endif--#if MIN_VERSION_fourmolu(0,8,1)--- emptyConfig now provided-#elif MIN_VERSION_fourmolu(0,7,0)-emptyConfig :: FourmoluConfig-emptyConfig =- FourmoluConfig- { cfgFilePrinterOpts = mempty- , cfgFileFixities = mempty- }-#else-emptyConfig :: FourmoluConfig-emptyConfig = mempty-#endif--{-- Backport FixityOverrides --}--#if MIN_VERSION_fourmolu(0,13,0)-addFixityOverrides :: FixityOverrides -> Config region -> Config region-addFixityOverrides fixities cfg = cfg{cfgFixityOverrides = fixities}-#elif MIN_VERSION_fourmolu(0,7,0)-type FixityOverrides = FixityMap--addFixityOverrides :: FixityOverrides -> Config region -> Config region-addFixityOverrides fixities cfg = cfg{cfgFixityOverrides = fixities}-#else-type FixityOverrides = ()--addFixityOverrides :: FixityOverrides -> Config region -> Config region-addFixityOverrides _ = id-#endif--{-- Backport ConfigParseError --}--#if MIN_VERSION_fourmolu(0,7,0)-showParseError :: Show parseException => parseException -> String-showParseError = show-#else-showParseError :: (pos, String) -> String-showParseError = snd-#endif