Skip to content

Commit

Permalink
Use specific versions of fourmolu for each version of GHC
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Aug 17, 2023
1 parent ee105ee commit a7d4c53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 84 deletions.
11 changes: 9 additions & 2 deletions plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ library
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.1.0.0
Expand All @@ -44,6 +42,15 @@ library
, text
, transformers

if impl(ghc >= 8.10) && impl(ghc < 9.0)
build-depends: fourmolu ^>= 0.9
elif 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.13
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
Expand Down
10 changes: 3 additions & 7 deletions plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Development.IDE.GHC.Compat as Compat hiding (Cpp, Warning,
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
Expand All @@ -43,6 +42,7 @@ import Language.LSP.Protocol.Message
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)
Expand Down Expand Up @@ -79,17 +79,13 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
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
, cfgFixityOverrides = cfgFileFixities fourmoluConfig
, cfgRegion = region
, cfgDebug = False
, cfgPrinterOpts =
Expand All @@ -112,7 +108,7 @@ provider recorder plId ideState typ contents fp fo = ExceptT $ withIndefinitePro
}
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)
where
fp' = fromNormalizedFilePath fp
title = "Formatting " <> T.pack (takeFileName fp')
Expand Down
75 changes: 0 additions & 75 deletions plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu/Shim.hs

This file was deleted.

0 comments on commit a7d4c53

Please sign in to comment.