Skip to content

Commit 13ed087

Browse files
committed
Clean up class plugin
1 parent 9f014e2 commit 13ed087

File tree

4 files changed

+33
-50
lines changed

4 files changed

+33
-50
lines changed

plugins/hls-class-plugin/hls-class-plugin.cabal

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ library
2525
hs-source-dirs: src
2626
build-depends:
2727
, aeson
28-
, base >=4.12 && <5
28+
, base >=4.12 && <5
2929
, containers
3030
, ghc
3131
, ghc-exactprint
32-
, ghcide >=1.2 && <1.4
33-
, hls-plugin-api ^>=1.1
32+
, ghcide >=1.2 && <1.4
33+
, hls-plugin-api ^>=1.1
3434
, lens
3535
, lsp
3636
, text
3737
, transformers
38-
, unordered-containers
3938

4039
default-language: Haskell2010
4140
default-extensions:
@@ -52,11 +51,8 @@ test-suite tests
5251
ghc-options: -threaded -rtsopts -with-rtsopts=-N
5352
build-depends:
5453
, base
55-
, bytestring
5654
, filepath
5755
, hls-class-plugin
58-
, hls-test-utils ^>= 1.0
56+
, hls-test-utils ^>=1.0
5957
, lens
60-
, lsp-test
6158
, lsp-types
62-
, text

plugins/hls-class-plugin/src/Ide/Plugin/Class.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import qualified Data.Text as T
2525
import Development.IDE hiding (pluginHandlers)
2626
import Development.IDE.Core.PositionMapping (fromCurrentRange,
2727
toCurrentRange)
28-
import Development.IDE.GHC.Compat hiding (getLoc)
28+
import Development.IDE.GHC.Compat
2929
import Development.IDE.Spans.AtPoint
3030
import qualified GHC.Generics as Generics
3131
import GhcPlugins hiding (Var, getLoc,
@@ -38,7 +38,6 @@ import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs, Parens)
3838
import Language.LSP.Server
3939
import Language.LSP.Types
4040
import qualified Language.LSP.Types.Lens as J
41-
import SrcLoc
4241
import TcEnv
4342
import TcRnMonad
4443

plugins/hls-class-plugin/test/Main.hs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
{-# LANGUAGE LambdaCase #-}
2-
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE ScopedTypeVariables #-}
4-
{-# LANGUAGE TypeOperators #-}
1+
{-# LANGUAGE LambdaCase #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE TypeOperators #-}
4+
5+
{-# OPTIONS_GHC -Wall #-}
56
module Main
67
( main
7-
)
8-
where
8+
) where
99

10-
import Control.Lens hiding ((<.>))
11-
import qualified Data.ByteString.Lazy as BS
12-
import qualified Data.Text.Encoding as T
10+
import Control.Lens (Prism', prism', (^..), (^?))
11+
import Control.Monad (void)
1312
import qualified Ide.Plugin.Class as Class
1413
import qualified Language.LSP.Types.Lens as J
1514
import System.FilePath
@@ -18,14 +17,14 @@ import Test.Hls
1817
main :: IO ()
1918
main = defaultTestRunner tests
2019

21-
plugin :: PluginDescriptor IdeState
22-
plugin = Class.descriptor "class"
20+
classPlugin :: PluginDescriptor IdeState
21+
classPlugin = Class.descriptor "class"
2322

2423
tests :: TestTree
2524
tests = testGroup
2625
"class"
2726
[ testCase "Produces addMinimalMethodPlaceholders code actions for one instance" $ do
28-
runSessionWithServer plugin classPath $ do
27+
runSessionWithServer classPlugin testDataDir $ do
2928
doc <- openDoc "T1.hs" "haskell"
3029
_ <- waitForDiagnosticsFromSource doc "typecheck"
3130
caResults <- getAllCodeActions doc
@@ -34,23 +33,17 @@ tests = testGroup
3433
[ Just "Add placeholders for '=='"
3534
, Just "Add placeholders for '/='"
3635
]
37-
, glodenTest "Creates a placeholder for '=='" "T1" "eq"
38-
$ \(eqAction:_) -> do
36+
, goldenWithClass "Creates a placeholder for '=='" "T1" "eq" $ \(eqAction:_) -> do
3937
executeCodeAction eqAction
40-
, glodenTest "Creates a placeholder for '/='" "T1" "ne"
41-
$ \(_:neAction:_) -> do
38+
, goldenWithClass "Creates a placeholder for '/='" "T1" "ne" $ \(_:neAction:_) -> do
4239
executeCodeAction neAction
43-
, glodenTest "Creates a placeholder for 'fmap'" "T2" "fmap"
44-
$ \(_:_:fmapAction:_) -> do
40+
, goldenWithClass "Creates a placeholder for 'fmap'" "T2" "fmap" $ \(_:_:fmapAction:_) -> do
4541
executeCodeAction fmapAction
46-
, glodenTest "Creates a placeholder for multiple methods 1" "T3" "1"
47-
$ \(mmAction:_) -> do
42+
, goldenWithClass "Creates a placeholder for multiple methods 1" "T3" "1" $ \(mmAction:_) -> do
4843
executeCodeAction mmAction
49-
, glodenTest "Creates a placeholder for multiple methods 2" "T3" "2"
50-
$ \(_:mmAction:_) -> do
44+
, goldenWithClass "Creates a placeholder for multiple methods 2" "T3" "2" $ \(_:mmAction:_) -> do
5145
executeCodeAction mmAction
52-
, glodenTest "Creates a placeholder for a method starting with '_'" "T4" ""
53-
$ \(_fAction:_) -> do
46+
, goldenWithClass "Creates a placeholder for a method starting with '_'" "T4" "" $ \(_fAction:_) -> do
5447
executeCodeAction _fAction
5548
]
5649

@@ -59,20 +52,13 @@ _CACodeAction = prism' InR $ \case
5952
InR action -> Just action
6053
_ -> Nothing
6154

62-
classPath :: FilePath
63-
classPath = "test" </> "testdata"
55+
goldenWithClass :: TestName -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
56+
goldenWithClass title path desc act =
57+
goldenWithHaskellDoc classPlugin title testDataDir path (desc <.> "expected") "hs" $ \doc -> do
58+
_ <- waitForDiagnosticsFromSource doc "typecheck"
59+
actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
60+
act actions
61+
void $ skipManyTill anyMessage (getDocumentEdit doc)
6462

65-
glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
66-
glodenTest name fp deco execute
67-
= goldenGitDiff name (classPath </> fpWithDeco <.> "expected" <.> "hs")
68-
$ runSessionWithServer plugin classPath
69-
$ do
70-
doc <- openDoc (fp <.> "hs") "haskell"
71-
_ <- waitForDiagnosticsFromSource doc "typecheck"
72-
actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
73-
execute actions
74-
BS.fromStrict . T.encodeUtf8 <$> skipManyTill anyMessage (getDocumentEdit doc)
75-
where
76-
fpWithDeco
77-
| deco == "" = fp
78-
| otherwise = fp <.> deco
63+
testDataDir :: FilePath
64+
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)