Skip to content

Commit cc4dea6

Browse files
authored
Extract last 2 plugins and clean up others (haskell#1836)
* Add goldenWithHaskellDoc test util * Extract module name plugin * Extract ormolu plugin * Clean up brittany plugin * Clean up class plugin * Clean up eval plugin * Clean up explicit imports plugin * Clean up floskell plugin * Clean up fourmolu plugin * Clean up haddock comments plugin * Clean up hlint plugin * Clean up pragmas plugin * Clean up refine imports plugin * Clean up retrie plugin * Clean up splice plugin * Clean up stylish haskell plugin * Fix formatter tests * Fix tests' hie.yaml * Clean up Wingman * Fix eval tests
1 parent a9113df commit cc4dea6

File tree

268 files changed

+1496
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+1496
-1122
lines changed

Diff for: cabal.project

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ packages:
2020
./plugins/hls-splice-plugin
2121
./plugins/hls-floskell-plugin
2222
./plugins/hls-pragmas-plugin
23+
./plugins/hls-module-name-plugin
24+
./plugins/hls-ormolu-plugin
2325
tests: true
2426

2527
package *

Diff for: haskell-language-server.cabal

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ extra-source-files:
2525
test/testdata/hlint/ignore/.hlint.yaml
2626
test/testdata/**/*.h
2727
test/testdata/**/*.hs
28-
test/testdata/**/*.expected
2928

3029
flag pedantic
3130
description: Enable -Werror
@@ -231,8 +230,7 @@ common hlint
231230

232231
common moduleName
233232
if flag(moduleName) || flag(all-plugins)
234-
hs-source-dirs: plugins/default/src
235-
other-modules: Ide.Plugin.ModuleName
233+
build-depends: hls-module-name-plugin ^>= 1.0.0.0
236234
cpp-options: -DmoduleName
237235

238236
common pragmas
@@ -259,9 +257,7 @@ common fourmolu
259257

260258
common ormolu
261259
if flag(ormolu) || flag(all-formatters)
262-
hs-source-dirs: plugins/default/src
263-
other-modules: Ide.Plugin.Ormolu
264-
build-depends: ormolu ^>=0.1.2
260+
build-depends: hls-ormolu-plugin ^>= 1.0.0.0
265261
cpp-options: -Dormolu
266262

267263
common stylishHaskell
@@ -414,7 +410,6 @@ test-suite func-test
414410
FunctionalLiquid
415411
HieBios
416412
Highlight
417-
ModuleName
418413
Progress
419414
Reference
420415
Rename

Diff for: hls-test-utils/src/Test/Hls.hs

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{-# LANGUAGE GADTs #-}
2-
{-# LANGUAGE LambdaCase #-}
1+
{-# LANGUAGE GADTs #-}
2+
{-# LANGUAGE LambdaCase #-}
3+
{-# LANGUAGE OverloadedStrings #-}
34
module Test.Hls
45
( module Test.Tasty.HUnit,
56
module Test.Tasty,
@@ -11,6 +12,8 @@ module Test.Hls
1112
module Control.Applicative.Combinators,
1213
defaultTestRunner,
1314
goldenGitDiff,
15+
goldenWithHaskellDoc,
16+
goldenWithHaskellDocFormatter,
1417
def,
1518
runSessionWithServer,
1619
runSessionWithServerFormatter,
@@ -30,6 +33,8 @@ import Control.Monad.IO.Class
3033
import Data.ByteString.Lazy (ByteString)
3134
import Data.Default (def)
3235
import qualified Data.Text as T
36+
import qualified Data.Text.Lazy as TL
37+
import qualified Data.Text.Lazy.Encoding as TL
3338
import Development.IDE (IdeState, hDuplicateTo',
3439
noLogging)
3540
import Development.IDE.Graph (ShakeOptions (shakeThreads))
@@ -46,6 +51,7 @@ import Language.LSP.Types
4651
import Language.LSP.Types.Capabilities (ClientCapabilities)
4752
import System.Directory (getCurrentDirectory,
4853
setCurrentDirectory)
54+
import System.FilePath
4955
import System.IO.Extra
5056
import System.IO.Unsafe (unsafePerformIO)
5157
import System.Process.Extra (createPipe)
@@ -67,6 +73,43 @@ gitDiff fRef fNew = ["git", "-c", "core.fileMode=false", "diff", "--no-index", "
6773
goldenGitDiff :: TestName -> FilePath -> IO ByteString -> TestTree
6874
goldenGitDiff name = goldenVsStringDiff name gitDiff
6975

76+
goldenWithHaskellDoc
77+
:: PluginDescriptor IdeState
78+
-> TestName
79+
-> FilePath
80+
-> FilePath
81+
-> FilePath
82+
-> FilePath
83+
-> (TextDocumentIdentifier -> Session ())
84+
-> TestTree
85+
goldenWithHaskellDoc plugin title testDataDir path desc ext act =
86+
goldenGitDiff title (testDataDir </> path <.> desc <.> ext)
87+
$ runSessionWithServer plugin testDataDir
88+
$ TL.encodeUtf8 . TL.fromStrict
89+
<$> do
90+
doc <- openDoc (path <.> ext) "haskell"
91+
act doc
92+
documentContents doc
93+
94+
goldenWithHaskellDocFormatter
95+
:: PluginDescriptor IdeState
96+
-> String
97+
-> TestName
98+
-> FilePath
99+
-> FilePath
100+
-> FilePath
101+
-> FilePath
102+
-> (TextDocumentIdentifier -> Session ())
103+
-> TestTree
104+
goldenWithHaskellDocFormatter plugin formatter title testDataDir path desc ext act =
105+
goldenGitDiff title (testDataDir </> path <.> desc <.> ext)
106+
$ runSessionWithServerFormatter plugin formatter testDataDir
107+
$ TL.encodeUtf8 . TL.fromStrict
108+
<$> do
109+
doc <- openDoc (path <.> ext) "haskell"
110+
act doc
111+
documentContents doc
112+
70113
runSessionWithServer :: PluginDescriptor IdeState -> FilePath -> Session a -> IO a
71114
runSessionWithServer plugin = runSessionWithServer' [plugin] def def fullCaps
72115

Diff for: nix/default.nix

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let
3333
hls-brittany-plugin = gitignoreSource ../plugins/hls-brittany-plugin;
3434
hls-stylish-haskell-plugin = gitignoreSource ../plugins/hls-stylish-haskell-plugin;
3535
hls-fourmolu-plugin = gitignoreSource ../plugins/hls-fourmolu-plugin;
36+
hls-ormolu-plugin = gitignoreSource ../plugins/hls-ormolu-plugin;
3637
hls-class-plugin = gitignoreSource ../plugins/hls-class-plugin;
3738
hls-haddock-comments-plugin = gitignoreSource ../plugins/hls-haddock-comments-plugin;
3839
hls-eval-plugin = gitignoreSource ../plugins/hls-eval-plugin;
@@ -44,6 +45,7 @@ let
4445
hls-tactics-plugin = gitignoreSource ../plugins/hls-tactics-plugin;
4546
hls-floskell-plugin = gitignoreSource ../plugins/hls-floskell-plugin;
4647
hls-pragmas-plugin = gitignoreSource ../plugins/hls-pragmas-plugin;
48+
hls-module-name-plugin = gitignoreSource ../plugins/hls-module-name-plugin;
4749
};
4850
gitignoreSource = (import sources.gitignore { inherit (pkgs) lib; }).gitignoreSource;
4951
extended = haskellPackages:

Diff for: plugins/default/src/Ide/Plugin/ModuleName.hs

-157
This file was deleted.

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

+1-2
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

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

+1-2
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)

Diff for: plugins/hls-brittany-plugin/test/Main.hs

+28-30
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 = goldenWithHaskellDocFormatter brittanyPlugin "brittany" title testDataDir path desc "hs"
35+
36+
testDataDir :: FilePath
37+
testDataDir = "test" </> "testdata"

Diff for: plugins/hls-brittany-plugin/test/testdata/hie.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cradle:
2+
direct:
3+
arguments: []

0 commit comments

Comments
 (0)