Skip to content

Commit bb6b4e1

Browse files
authored
Support fourmolu ^>= 0.7 (#2944)
1 parent 140f904 commit bb6b4e1

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

Diff for: plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@ license: Apache-2.0
99
license-file: LICENSE
1010
author: The Haskell IDE Team
1111
copyright: The Haskell IDE Team
12+
homepage: https://github.com/haskell/haskell-language-server
13+
bug-reports: https://github.com/haskell/haskell-language-server/issues
1214
maintainer: [email protected]
1315
category: Development
1416
build-type: Simple
1517
extra-source-files:
1618
LICENSE
1719
test/testdata/**/*.hs
1820

21+
source-repository head
22+
type: git
23+
location: git://github.com/haskell/haskell-language-server.git
24+
1925
library
2026
exposed-modules: Ide.Plugin.Fourmolu
2127
hs-source-dirs: src
2228
ghc-options: -Wall
2329
build-depends:
2430
, base >=4.12 && <5
2531
, filepath
26-
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6
32+
, fourmolu ^>=0.3 || ^>=0.4 || ^>= 0.6 || ^>= 0.7
2733
, ghc
2834
, ghc-boot-th
2935
, ghcide ^>=1.7

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

+39-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DataKinds #-}
13
{-# LANGUAGE DisambiguateRecordFields #-}
24
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE OverloadedLabels #-}
36
{-# LANGUAGE OverloadedStrings #-}
47
{-# LANGUAGE TypeApplications #-}
5-
{-# LANGUAGE DataKinds #-}
6-
{-# LANGUAGE OverloadedLabels #-}
78

89
module Ide.Plugin.Fourmolu (
910
descriptor,
@@ -23,16 +24,18 @@ import Development.IDE.GHC.Compat as Compat hiding (Cpp)
2324
import qualified Development.IDE.GHC.Compat.Util as S
2425
import GHC.LanguageExtensions.Type (Extension (Cpp))
2526
import Ide.Plugin.Properties
26-
import Ide.PluginUtils (makeDiffTextEdit, usePropertyLsp)
27+
import Ide.PluginUtils (makeDiffTextEdit,
28+
usePropertyLsp)
2729
import Ide.Types
2830
import Language.LSP.Server hiding (defaultConfig)
2931
import Language.LSP.Types
3032
import Language.LSP.Types.Lens (HasTabSize (tabSize))
3133
import Ormolu
34+
import Ormolu.Config
3235
import System.Exit
3336
import System.FilePath
3437
import System.IO (stderr)
35-
import System.Process.Run (proc, cwd)
38+
import System.Process.Run (cwd, proc)
3639
import System.Process.Text (readCreateProcessWithExitCode)
3740

3841
descriptor :: PluginId -> PluginDescriptor IdeState
@@ -78,10 +81,17 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell
7881
ExitFailure n ->
7982
pure . Left . responseError $ "Fourmolu failed with exit code " <> T.pack (show n)
8083
else do
81-
let format printerOpts =
84+
let format fourmoluConfig =
8285
first (mkError . show)
8386
<$> try @OrmoluException (makeDiffTextEdit contents <$> ormolu config fp' (T.unpack contents))
8487
where
88+
printerOpts =
89+
#if MIN_VERSION_fourmolu(0,7,0)
90+
cfgFilePrinterOpts fourmoluConfig
91+
#else
92+
fourmoluConfig
93+
94+
#endif
8595
config =
8696
defaultConfig
8797
{ cfgDynOptions = map DynOption fileOpts
@@ -91,6 +101,10 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell
91101
fillMissingPrinterOpts
92102
(printerOpts <> lspPrinterOpts)
93103
defaultPrinterOpts
104+
#if MIN_VERSION_fourmolu(0,7,0)
105+
, cfgFixityOverrides =
106+
cfgFileFixities fourmoluConfig
107+
#endif
94108
}
95109
in liftIO (loadConfigFile fp') >>= \case
96110
ConfigLoaded file opts -> liftIO $ do
@@ -101,16 +115,33 @@ provider plId ideState typ contents fp fo = withIndefiniteProgress title Cancell
101115
. unlines
102116
$ ("No " ++ show configFileName ++ " found in any of:") :
103117
map (" " ++) searchDirs
104-
format mempty
105-
ConfigParseError f (_, err) -> do
118+
format emptyOptions
119+
where
120+
emptyOptions =
121+
#if MIN_VERSION_fourmolu(0,7,0)
122+
FourmoluConfig
123+
{ cfgFilePrinterOpts = mempty
124+
, cfgFileFixities = mempty
125+
}
126+
#else
127+
mempty
128+
#endif
129+
130+
ConfigParseError f err -> do
106131
sendNotification SWindowShowMessage $
107132
ShowMessageParams
108133
{ _xtype = MtError
109134
, _message = errorMessage
110135
}
111136
return . Left $ responseError errorMessage
112137
where
113-
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack err
138+
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (convertErr err)
139+
convertErr =
140+
#if MIN_VERSION_fourmolu(0,7,0)
141+
show
142+
#else
143+
snd
144+
#endif
114145
where
115146
fp' = fromNormalizedFilePath fp
116147
title = "Formatting " <> T.pack (takeFileName fp')

0 commit comments

Comments
 (0)