Skip to content

Commit f653555

Browse files
committed
Clean up fourmolu plugin
1 parent 00c51b0 commit f653555

File tree

8 files changed

+33
-52
lines changed

8 files changed

+33
-52
lines changed

plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ library
2020
exposed-modules: Ide.Plugin.Fourmolu
2121
hs-source-dirs: src
2222
build-depends:
23-
, base >=4.12 && <5
24-
, extra
25-
, fourmolu ^>=0.3
23+
, base >=4.12 && <5
2624
, filepath
25+
, fourmolu ^>=0.3
2726
, ghc
2827
, ghc-boot-th
29-
, ghcide >=1.2 && <1.4
28+
, ghcide >=1.2 && <1.4
3029
, hls-plugin-api ^>=1.1
3130
, lens
3231
, lsp
33-
, lsp-types
3432
, text
3533

3634
default-language: Haskell2010
@@ -43,18 +41,7 @@ test-suite tests
4341
ghc-options: -threaded -rtsopts -with-rtsopts=-N
4442
build-depends:
4543
, base
46-
, bytestring
47-
, hls-fourmolu-plugin
48-
, text
49-
, data-default
50-
, hspec-expectations
51-
, lens
52-
, ghcide
5344
, filepath
54-
, hls-test-utils ^>= 1.0
55-
, lsp-types
56-
, aeson
57-
, hls-plugin-api
45+
, hls-fourmolu-plugin
46+
, hls-test-utils ^>=1.0
5847
, lsp-test
59-
, containers
60-
, unordered-containers

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@ module Ide.Plugin.Fourmolu (
99
provider,
1010
) where
1111

12-
import Control.Exception
13-
import Data.Either.Extra
14-
import System.FilePath
15-
12+
import Control.Exception (try)
1613
import Control.Lens ((^.))
14+
import Control.Monad.IO.Class
15+
import Data.Bifunctor (first)
1716
import qualified Data.Text as T
18-
import Development.IDE as D hiding (pluginHandlers)
17+
import Development.IDE hiding (pluginHandlers)
18+
import Development.IDE.GHC.Compat (moduleNameString)
1919
import qualified DynFlags as D
2020
import qualified EnumSet as S
21-
import GHC (DynFlags, moduleNameString)
2221
import GHC.LanguageExtensions.Type (Extension (Cpp))
2322
import GhcPlugins (HscEnv (hsc_dflags))
2423
import Ide.PluginUtils (makeDiffTextEdit)
25-
26-
import Control.Monad.IO.Class
2724
import Ide.Types
2825
import Language.LSP.Server hiding (defaultConfig)
2926
import Language.LSP.Types
3027
import Language.LSP.Types.Lens
3128
import "fourmolu" Ormolu
29+
import System.FilePath
3230

3331
-- ---------------------------------------------------------------------
3432

@@ -48,7 +46,7 @@ provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable
4846
Just df -> liftIO $ convertDynFlags df
4947

5048
let format printerOpts =
51-
mapLeft (responseError . ("Fourmolu: " <>) . T.pack . show)
49+
first (responseError . ("Fourmolu: " <>) . T.pack . show)
5250
<$> try @OrmoluException (makeDiffTextEdit contents <$> ormolu config fp' (T.unpack contents))
5351
where
5452
config =
@@ -91,7 +89,7 @@ provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable
9189
FormatRange (Range (Position sl _) (Position el _)) ->
9290
RegionIndices (Just $ sl + 1) (Just $ el + 1)
9391

94-
convertDynFlags :: DynFlags -> IO [DynOption]
92+
convertDynFlags :: D.DynFlags -> IO [DynOption]
9593
convertDynFlags df =
9694
let pp = ["-pgmF=" <> p | not (null p)]
9795
p = D.sPgm_F $ D.settings df
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
module Main(main) where
2+
module Main
3+
( main
4+
) where
35

4-
import Control.Monad.IO.Class
5-
import Data.Aeson
6-
import qualified Data.ByteString.Lazy as BS
7-
import qualified Data.Text.Encoding as T
8-
import qualified Data.Text.IO as T
6+
import qualified Ide.Plugin.Fourmolu as Fourmolu
97
import Language.LSP.Test
108
import Language.LSP.Types
11-
import Test.Hls
12-
import qualified Ide.Plugin.Fourmolu as Fourmolu
139
import System.FilePath
10+
import Test.Hls
1411

1512
main :: IO ()
1613
main = defaultTestRunner tests
1714

18-
plugin :: PluginDescriptor IdeState
19-
plugin = Fourmolu.descriptor "fourmolu"
20-
21-
testDataDir :: FilePath
22-
testDataDir = "test/testdata/"
15+
fourmoluPlugin :: PluginDescriptor IdeState
16+
fourmoluPlugin = Fourmolu.descriptor "fourmolu"
2317

2418
tests :: TestTree
2519
tests = testGroup "fourmolu"
26-
[ goldenGitDiff "formats correctly" (testDataDir </> "Format.fourmolu.formatted.hs") $
27-
runSessionWithServerFormatter plugin "fourmolu" testDataDir $ do
28-
doc <- openDoc "Format.hs" "haskell"
29-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
30-
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
31-
, goldenGitDiff "formats imports correctly" (testDataDir </> "Format2.fourmolu.formatted.hs") $
32-
runSessionWithServerFormatter plugin "fourmolu" testDataDir $ do
33-
doc <- openDoc "Format2.hs" "haskell"
34-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
35-
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
20+
[ goldenWithFourmolu "formats correctly" "Fourmolu" "formatted" $ \doc -> do
21+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
22+
, goldenWithFourmolu "formats imports correctly" "Fourmolu" "formatted" $ \doc -> do
23+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
3624
]
25+
26+
goldenWithFourmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
27+
goldenWithFourmolu title path desc = goldenWithHaskellDoc fourmoluPlugin title testDataDir path desc "hs"
28+
29+
testDataDir :: FilePath
30+
testDataDir = "test" </> "testdata"

plugins/hls-fourmolu-plugin/test/testdata/Format.hs renamed to plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Format where
1+
module Fourmolu where
22
import Data.List
33

44
import Prelude
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cradle:
2+
direct:

0 commit comments

Comments
 (0)