Skip to content

Commit 9f014e2

Browse files
committed
Clean up brittany plugin
1 parent 0a9b876 commit 9f014e2

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

plugins/hls-brittany-plugin/hls-brittany-plugin.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ test-suite tests
4242
ghc-options: -threaded -rtsopts -with-rtsopts=-N
4343
build-depends:
4444
, base
45-
, bytestring
45+
, filepath
4646
, hls-brittany-plugin
4747
, hls-test-utils ^>=1.0
48-
, text

plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Control.Exception (bracket_)
66
import Control.Lens
77
import Control.Monad.IO.Class
88
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
9-
import Data.Coerce
109
import Data.Maybe (mapMaybe, maybeToList)
1110
import Data.Semigroup
1211
import Data.Text (Text)
@@ -81,7 +80,7 @@ runBrittany :: Int -- ^ tab size
8180
runBrittany tabSize df confPath text = do
8281
let cfg = mempty
8382
{ _conf_layout =
84-
mempty { _lconfig_indentAmount = opt (coerce tabSize)
83+
mempty { _lconfig_indentAmount = opt (Last tabSize)
8584
}
8685
, _conf_forward =
8786
(mempty :: CForwardOptions Option)
Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
module Main(main) where
2+
module Main
3+
( main
4+
) where
35

4-
import qualified Data.ByteString.Lazy as BS
5-
import qualified Data.Text.Encoding as T
6-
import qualified Data.Text.IO as T
7-
import qualified Ide.Plugin.Brittany as Brittany
6+
import qualified Ide.Plugin.Brittany as Brittany
7+
import System.FilePath
88
import Test.Hls
99

1010
main :: IO ()
1111
main = defaultTestRunner tests
1212

13-
plugin :: PluginDescriptor IdeState
14-
plugin = Brittany.descriptor "brittany"
13+
brittanyPlugin :: PluginDescriptor IdeState
14+
brittanyPlugin = Brittany.descriptor "brittany"
1515

1616
tests :: TestTree
17-
tests = testGroup "brittany" [
18-
goldenGitDiff "formats a document with LF endings" "test/testdata/BrittanyLF.formatted_document.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
19-
doc <- openDoc "BrittanyLF.hs" "haskell"
20-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
21-
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
22-
23-
, goldenGitDiff "formats a document with CRLF endings" "test/testdata/BrittanyCRLF.formatted_document.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
24-
doc <- openDoc "BrittanyCRLF.hs" "haskell"
25-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
26-
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
27-
28-
, goldenGitDiff "formats a range with LF endings" "test/testdata/BrittanyLF.formatted_range.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
29-
doc <- openDoc "BrittanyLF.hs" "haskell"
30-
let range = Range (Position 1 0) (Position 2 22)
31-
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
32-
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
33-
34-
, goldenGitDiff "formats a range with CRLF endings" "test/testdata/BrittanyCRLF.formatted_range.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
35-
doc <- openDoc "BrittanyCRLF.hs" "haskell"
36-
let range = Range (Position 1 0) (Position 2 22)
37-
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
38-
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
39-
]
17+
tests = testGroup "brittany"
18+
[ brittanyGolden "formats a document with LF endings" "BrittanyLF" "formatted_document" $ \doc -> do
19+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
20+
21+
, brittanyGolden "formats a document with CRLF endings" "BrittanyCRLF" "formatted_document" $ \doc -> do
22+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
23+
24+
, brittanyGolden "formats a range with LF endings" "BrittanyLF" "formatted_range" $ \doc -> do
25+
let range = Range (Position 1 0) (Position 2 22)
26+
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
27+
28+
, brittanyGolden "formats a range with CRLF endings" "BrittanyCRLF" "formatted_range" $ \doc -> do
29+
let range = Range (Position 1 0) (Position 2 22)
30+
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
31+
]
32+
33+
brittanyGolden :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
34+
brittanyGolden title path desc = goldenWithHaskellDoc brittanyPlugin title testDataDir path desc "hs"
35+
36+
testDataDir :: FilePath
37+
testDataDir = "test" </> "testdata"
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)