Skip to content

Commit 00c51b0

Browse files
committed
Clean up floskell plugin
1 parent 717b1ff commit 00c51b0

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

plugins/hls-floskell-plugin/hls-floskell-plugin.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ library
2020
exposed-modules: Ide.Plugin.Floskell
2121
hs-source-dirs: src
2222
build-depends:
23-
, base >=4.12 && <5
24-
, floskell ^>=0.10
25-
, ghcide >=1.2 && <1.4
23+
, base >=4.12 && <5
24+
, floskell ^>=0.10
25+
, ghcide >=1.2 && <1.4
2626
, hls-plugin-api ^>=1.1
2727
, lsp-types
2828
, text
@@ -38,6 +38,6 @@ test-suite tests
3838
ghc-options: -threaded -rtsopts -with-rtsopts=-N
3939
build-depends:
4040
, base
41+
, filepath
4142
, hls-floskell-plugin
4243
, hls-test-utils ^>=1.0
43-
, text

plugins/hls-floskell-plugin/src/Ide/Plugin/Floskell.hs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE ScopedTypeVariables #-}
1+
{-# LANGUAGE OverloadedStrings #-}
32

43
module Ide.Plugin.Floskell
5-
(
6-
descriptor
4+
( descriptor
75
, provider
8-
)
9-
where
6+
) where
107

118
import Control.Monad.IO.Class
129
import qualified Data.Text as T
1310
import qualified Data.Text.Lazy as TL
1411
import qualified Data.Text.Lazy.Encoding as TL
15-
import Development.IDE as D hiding (pluginHandlers)
12+
import Development.IDE hiding (pluginHandlers)
1613
import Floskell
1714
import Ide.PluginUtils
1815
import Ide.Types
@@ -37,10 +34,10 @@ provider _ideState typ contents fp _ = liftIO $ do
3734
let (range, selectedContents) = case typ of
3835
FormatText -> (fullRange contents, contents)
3936
FormatRange r -> (r, extractRange r contents)
40-
result = reformat config (Just file) (TL.encodeUtf8 (TL.fromStrict selectedContents))
37+
result = reformat config (Just file) . TL.encodeUtf8 $ TL.fromStrict selectedContents
4138
case result of
42-
Left err -> return $ Left $ responseError (T.pack $ "floskellCmd: " ++ err)
43-
Right new -> return $ Right $ List [TextEdit range . TL.toStrict $ TL.decodeUtf8 new]
39+
Left err -> pure $ Left $ responseError $ T.pack $ "floskellCmd: " ++ err
40+
Right new -> pure $ Right $ List [TextEdit range . TL.toStrict $ TL.decodeUtf8 new]
4441

4542
-- | Find Floskell Config, user and system wide or provides a default style.
4643
-- Every directory of the filepath will be searched to find a user configuration.
@@ -53,6 +50,6 @@ findConfigOrDefault file = do
5350
Just confFile -> readAppConfig confFile
5451
Nothing ->
5552
let gibiansky = head (filter (\s -> styleName s == "gibiansky") styles)
56-
in return $ defaultAppConfig { appStyle = gibiansky }
53+
in pure $ defaultAppConfig { appStyle = gibiansky }
5754

5855
-- ---------------------------------------------------------------------
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
module Main(main) where
2+
module Main
3+
( main
4+
) where
35

4-
import qualified Data.Text.Lazy as TL
5-
import qualified Data.Text.Lazy.Encoding as TL
6-
import qualified Ide.Plugin.Floskell as Floskell
6+
import qualified Ide.Plugin.Floskell as Floskell
7+
import System.FilePath
78
import Test.Hls
89

910
main :: IO ()
1011
main = defaultTestRunner tests
1112

12-
plugin :: PluginDescriptor IdeState
13-
plugin = Floskell.descriptor "floskell"
13+
floskellPlugin :: PluginDescriptor IdeState
14+
floskellPlugin = Floskell.descriptor "floskell"
1415

1516
tests :: TestTree
1617
tests = testGroup "floskell"
17-
[ goldenGitDiff "formats a document" "test/testdata/Floskell.formatted_document.hs" $ runSessionWithServerFormatter plugin "floskell" "test/testdata" $ do
18-
doc <- openDoc "Floskell.hs" "haskell"
19-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
20-
TL.encodeUtf8 . TL.fromStrict <$> documentContents doc
18+
[ goldenWithFloskell "formats a document" "Floskell" "formatted_document" $ \doc -> do
19+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
2120

22-
, goldenGitDiff "formats a range" "test/testdata/Floskell.formatted_range.hs" $ runSessionWithServerFormatter plugin "floskell" "test/testdata" $ do
23-
doc <- openDoc "Floskell.hs" "haskell"
21+
, goldenWithFloskell "formats a range" "Floskell" "formatted_range" $ \doc -> do
2422
let range = Range (Position 1 0) (Position 4 22)
2523
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
26-
TL.encodeUtf8 . TL.fromStrict <$> documentContents doc
2724
]
25+
26+
goldenWithFloskell :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
27+
goldenWithFloskell title path desc = goldenWithHaskellDoc floskellPlugin title testDataDir path desc "hs"
28+
29+
testDataDir :: FilePath
30+
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)