@@ -12,6 +12,7 @@ module Main
12
12
import Control.Lens (Prism' , prism' , (^.) , (^..) , (^?) )
13
13
import Control.Monad (void )
14
14
import Data.Maybe
15
+ import qualified Data.Text as T
15
16
import qualified Ide.Plugin.Class as Class
16
17
import qualified Language.LSP.Types.Lens as J
17
18
import System.FilePath
@@ -31,23 +32,21 @@ tests = testGroup
31
32
codeActionTests :: TestTree
32
33
codeActionTests = testGroup
33
34
" code actions"
34
- [ testCase " Produces addMinimalMethodPlaceholders code actions for one instance" $ do
35
- runSessionWithServer classPlugin testDataDir $ do
36
- doc <- openDoc " T1.hs" " haskell"
37
- _ <- waitForDiagnosticsFromSource doc " typecheck"
38
- caResults <- getAllCodeActions doc
39
- liftIO $ map (^? _CACodeAction . J. title) caResults
40
- @?=
41
- [ Just " Add placeholders for '=='"
42
- , Just " Add placeholders for '==' with signature(s)"
43
- , Just " Add placeholders for '/='"
44
- , Just " Add placeholders for '/=' with signature(s)"
45
- ]
35
+ [ expectCodeActionsAvailable " Produces addMinimalMethodPlaceholders code actions for one instance" " T1"
36
+ [ " Add placeholders for '=='"
37
+ , " Add placeholders for '==' with signature(s)"
38
+ , " Add placeholders for '/='"
39
+ , " Add placeholders for '/=' with signature(s)"
40
+ , " Add placeholders for all missing methods"
41
+ , " Add placeholders for all missing methods with signature(s)"
42
+ ]
46
43
, goldenWithClass " Creates a placeholder for '=='" " T1" " eq" $ \ (eqAction: _) -> do
47
44
executeCodeAction eqAction
48
45
, goldenWithClass " Creates a placeholder for '/='" " T1" " ne" $ \ (_: _: neAction: _) -> do
49
46
executeCodeAction neAction
50
- , goldenWithClass " Creates a placeholder for 'fmap'" " T2" " fmap" $ \ (_: _: _: _: fmapAction: _) -> do
47
+ , goldenWithClass " Creates a placeholder for both '==' and '/='" " T1" " all" $ \ (_: _: _: _: allMethodsAction: _) -> do
48
+ executeCodeAction allMethodsAction
49
+ , goldenWithClass " Creates a placeholder for 'fmap'" " T2" " fmap" $ \ (_: _: _: _: _: _: fmapAction: _) -> do
51
50
executeCodeAction fmapAction
52
51
, goldenWithClass " Creates a placeholder for multiple methods 1" " T3" " 1" $ \ (mmAction: _) -> do
53
52
executeCodeAction mmAction
@@ -70,6 +69,11 @@ codeActionTests = testGroup
70
69
executeCodeAction eqWithSig
71
70
, goldenWithClass " Only insert pragma once" " InsertPragmaOnce" " " $ \ (_: multi: _) -> do
72
71
executeCodeAction multi
72
+ , expectCodeActionsAvailable " No code action available when minimal requirements meet" " MinimalDefinitionMeet" []
73
+ , expectCodeActionsAvailable " Add placeholders for all missing methods is unavailable when all methods are required" " AllMethodsRequired"
74
+ [ " Add placeholders for 'f','g'"
75
+ , " Add placeholders for 'f','g' with signature(s)"
76
+ ]
73
77
]
74
78
75
79
codeLensTests :: TestTree
@@ -99,7 +103,6 @@ _CACodeAction = prism' InR $ \case
99
103
InR action -> Just action
100
104
_ -> Nothing
101
105
102
-
103
106
goldenCodeLens :: TestName -> FilePath -> Int -> TestTree
104
107
goldenCodeLens title path idx =
105
108
goldenWithHaskellDoc classPlugin title testDataDir path " expected" " hs" $ \ doc -> do
@@ -115,5 +118,17 @@ goldenWithClass title path desc act =
115
118
act actions
116
119
void $ skipManyTill anyMessage (getDocumentEdit doc)
117
120
121
+ expectCodeActionsAvailable :: TestName -> FilePath -> [T. Text ] -> TestTree
122
+ expectCodeActionsAvailable title path actionTitles =
123
+ testCase title $ do
124
+ runSessionWithServer classPlugin testDataDir $ do
125
+ doc <- openDoc (path <.> " hs" ) " haskell"
126
+ _ <- waitForDiagnosticsFromSource doc " typecheck"
127
+ caResults <- getAllCodeActions doc
128
+ liftIO $ map (^? _CACodeAction . J. title) caResults
129
+ @?= expectedActions
130
+ where
131
+ expectedActions = Just <$> actionTitles
132
+
118
133
testDataDir :: FilePath
119
134
testDataDir = " test" </> " testdata"
0 commit comments