2
2
{-# LANGUAGE OverloadedLabels #-}
3
3
{-# LANGUAGE OverloadedLists #-}
4
4
{-# LANGUAGE OverloadedStrings #-}
5
- {-# OPTIONS_GHC -Wall #-}
6
- {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
7
5
8
6
module Main
9
7
( main
@@ -13,10 +11,10 @@ import Control.Exception (catch)
13
11
import Control.Lens (Prism' , prism' , view , (^.) ,
14
12
(^..) , (^?) )
15
13
import Control.Monad (void )
14
+ import Data.Foldable (find )
16
15
import Data.Maybe
17
16
import Data.Row ((.==) )
18
17
import qualified Data.Text as T
19
- import Development.IDE.Core.Compile (sourceTypecheck )
20
18
import qualified Ide.Plugin.Class as Class
21
19
import qualified Language.LSP.Protocol.Lens as L
22
20
import Language.LSP.Protocol.Message
@@ -47,35 +45,35 @@ codeActionTests = testGroup
47
45
, " Add placeholders for all missing methods"
48
46
, " Add placeholders for all missing methods with signature(s)"
49
47
]
50
- , goldenWithClass " Creates a placeholder for '=='" " T1" " eq" $ \ (eqAction : _) -> do
51
- executeCodeAction eqAction
52
- , goldenWithClass " Creates a placeholder for '/='" " T1" " ne" $ \ (_ : _ : neAction : _) -> do
53
- executeCodeAction neAction
54
- , goldenWithClass " Creates a placeholder for both '==' and '/='" " T1" " all" $ \ (_ : _ : _ : _ : allMethodsAction : _) -> do
55
- executeCodeAction allMethodsAction
56
- , goldenWithClass " Creates a placeholder for 'fmap'" " T2" " fmap" $ \ (_ : _ : _ : _ : _ : _ : fmapAction : _) -> do
57
- executeCodeAction fmapAction
58
- , goldenWithClass " Creates a placeholder for multiple methods 1" " T3" " 1" $ \ (mmAction : _) -> do
59
- executeCodeAction mmAction
60
- , goldenWithClass " Creates a placeholder for multiple methods 2" " T3" " 2" $ \ (_ : _ : mmAction : _) -> do
61
- executeCodeAction mmAction
62
- , goldenWithClass " Creates a placeholder for a method starting with '_'" " T4" " " $ \ (_fAction : _) -> do
63
- executeCodeAction _fAction
64
- , goldenWithClass " Creates a placeholder for '==' with extra lines" " T5" " " $ \ (eqAction : _) -> do
65
- executeCodeAction eqAction
66
- , goldenWithClass " Creates a placeholder for only the unimplemented methods of multiple methods" " T6" " 1" $ \ (gAction : _) -> do
67
- executeCodeAction gAction
68
- , goldenWithClass " Creates a placeholder for other two methods" " T6" " 2" $ \ (_ : _ : ghAction : _) -> do
69
- executeCodeAction ghAction
48
+ , goldenWithClass " Creates a placeholder for '=='" " T1" " eq" $
49
+ getActionByTitle " Add placeholders for '==' "
50
+ , goldenWithClass " Creates a placeholder for '/='" " T1" " ne" $
51
+ getActionByTitle " Add placeholders for '/=' "
52
+ , goldenWithClass " Creates a placeholder for both '==' and '/='" " T1" " all" $
53
+ getActionByTitle " Add placeholders for all missing methods "
54
+ , goldenWithClass " Creates a placeholder for 'fmap'" " T2" " fmap" $
55
+ getActionByTitle " Add placeholders for 'fmap' "
56
+ , goldenWithClass " Creates a placeholder for multiple methods 1" " T3" " 1" $
57
+ getActionByTitle " Add placeholders for 'f','g' "
58
+ , goldenWithClass " Creates a placeholder for multiple methods 2" " T3" " 2" $
59
+ getActionByTitle " Add placeholders for 'g','h' "
60
+ , goldenWithClass " Creates a placeholder for a method starting with '_'" " T4" " " $
61
+ getActionByTitle " Add placeholders for '_f' "
62
+ , goldenWithClass " Creates a placeholder for '==' with extra lines" " T5" " " $
63
+ getActionByTitle " Add placeholders for '==' "
64
+ , goldenWithClass " Creates a placeholder for only the unimplemented methods of multiple methods" " T6" " 1" $
65
+ getActionByTitle " Add placeholders for 'g' "
66
+ , goldenWithClass " Creates a placeholder for other two methods" " T6" " 2" $
67
+ getActionByTitle " Add placeholders for 'g','h' "
70
68
, onlyRunForGhcVersions [GHC92 , GHC94 ] " Only ghc-9.2+ enabled GHC2021 implicitly" $
71
- goldenWithClass " Don't insert pragma with GHC2021" " InsertWithGHC2021Enabled" " " $ \ (_ : eqWithSig : _) -> do
72
- executeCodeAction eqWithSig
73
- , goldenWithClass " Insert pragma if not exist" " InsertWithoutPragma" " " $ \ (_ : eqWithSig : _) -> do
74
- executeCodeAction eqWithSig
75
- , goldenWithClass " Don't insert pragma if exist" " InsertWithPragma" " " $ \ (_ : eqWithSig : _) -> do
76
- executeCodeAction eqWithSig
77
- , goldenWithClass " Only insert pragma once" " InsertPragmaOnce" " " $ \ (_ : multi : _) -> do
78
- executeCodeAction multi
69
+ goldenWithClass " Don't insert pragma with GHC2021" " InsertWithGHC2021Enabled" " " $
70
+ getActionByTitle " Add placeholders for '==' with signature(s) "
71
+ , goldenWithClass " Insert pragma if not exist" " InsertWithoutPragma" " " $
72
+ getActionByTitle " Add placeholders for '==' with signature(s) "
73
+ , goldenWithClass " Don't insert pragma if exist" " InsertWithPragma" " " $
74
+ getActionByTitle " Add placeholders for '==' with signature(s) "
75
+ , goldenWithClass " Only insert pragma once" " InsertPragmaOnce" " " $
76
+ getActionByTitle " Add placeholders for 'pure','<*>' with signature(s) "
79
77
, expectCodeActionsAvailable " No code action available when minimal requirements meet" " MinimalDefinitionMeet" []
80
78
, expectCodeActionsAvailable " Add placeholders for all missing methods is unavailable when all methods are required" " AllMethodsRequired"
81
79
[ " Add placeholders for 'f','g'"
@@ -162,14 +160,20 @@ goldenCodeLens title path idx =
162
160
executeCommand $ fromJust $ (lens !! idx) ^. L. command
163
161
void $ skipManyTill anyMessage (message SMethod_WorkspaceApplyEdit )
164
162
165
- goldenWithClass :: TestName -> FilePath -> FilePath -> ([CodeAction ] -> Session () ) -> TestTree
166
- goldenWithClass title path desc act =
163
+ goldenWithClass :: TestName -> FilePath -> FilePath -> ([CodeAction ] -> Session CodeAction ) -> TestTree
164
+ goldenWithClass title path desc findAction =
167
165
goldenWithHaskellDoc def classPlugin title testDataDir path (desc <.> " expected" ) " hs" $ \ doc -> do
168
166
_ <- waitForDiagnosticsFrom doc
169
167
actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
170
- act actions
168
+ action <- findAction actions
169
+ executeCodeAction action
171
170
void $ skipManyTill anyMessage (getDocumentEdit doc)
172
171
172
+ getActionByTitle :: T. Text -> [CodeAction ] -> Session CodeAction
173
+ getActionByTitle title actions = case find (\ a -> a ^. L. title == title) actions of
174
+ Just a -> pure a
175
+ Nothing -> liftIO $ assertFailure $ " Action " <> show title <> " not found in " <> show [a ^. L. title | a <- actions]
176
+
173
177
expectCodeActionsAvailable :: TestName -> FilePath -> [T. Text ] -> TestTree
174
178
expectCodeActionsAvailable title path actionTitles =
175
179
testCase title $ do
0 commit comments