@@ -846,7 +846,7 @@ typeWildCardActionTests = testGroup "type wildcard actions"
846
846
]
847
847
doc <- createDoc " Testing.hs" " haskell" content
848
848
_ <- waitForDiagnostics
849
- actionsOrCommands <- getCodeActions doc ( Range ( Position 2 1 ) ( Position 2 10 ))
849
+ actionsOrCommands <- getAllCodeActions doc
850
850
let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
851
851
, " Use type signature" `T.isInfixOf` actionTitle
852
852
]
@@ -866,7 +866,7 @@ typeWildCardActionTests = testGroup "type wildcard actions"
866
866
]
867
867
doc <- createDoc " Testing.hs" " haskell" content
868
868
_ <- waitForDiagnostics
869
- actionsOrCommands <- getCodeActions doc ( Range ( Position 2 1 ) ( Position 2 10 ))
869
+ actionsOrCommands <- getAllCodeActions doc
870
870
let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
871
871
, " Use type signature" `T.isInfixOf` actionTitle
872
872
]
@@ -889,7 +889,7 @@ typeWildCardActionTests = testGroup "type wildcard actions"
889
889
]
890
890
doc <- createDoc " Testing.hs" " haskell" content
891
891
_ <- waitForDiagnostics
892
- actionsOrCommands <- getCodeActions doc ( Range ( Position 4 1 ) ( Position 4 10 ))
892
+ actionsOrCommands <- getAllCodeActions doc
893
893
let [addSignature] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands
894
894
, " Use type signature" `T.isInfixOf` actionTitle
895
895
]
@@ -1111,7 +1111,7 @@ removeImportTests = testGroup "remove import actions"
1111
1111
doc <- createDoc " ModuleC.hs" " haskell" content
1112
1112
_ <- waitForDiagnostics
1113
1113
[_, _, _, _, InR action@ CodeAction { _title = actionTitle }]
1114
- <- getCodeActions doc ( Range ( Position 2 0 ) ( Position 2 5 ))
1114
+ <- nub <$> getAllCodeActions doc
1115
1115
liftIO $ " Remove all redundant imports" @=? actionTitle
1116
1116
executeCodeAction action
1117
1117
contentAfterAction <- documentContents doc
@@ -1149,7 +1149,7 @@ extendImportTests = testGroup "extend import actions"
1149
1149
, " import ModuleA as A (stuffB)"
1150
1150
, " main = print (stuffA, stuffB)"
1151
1151
])
1152
- (Range (Position 3 17 ) (Position 3 18 ))
1152
+ (Range (Position 2 17 ) (Position 2 18 ))
1153
1153
[" Add stuffA to the import list of ModuleA" ]
1154
1154
(T. unlines
1155
1155
[ " module ModuleB where"
@@ -1169,7 +1169,7 @@ extendImportTests = testGroup "extend import actions"
1169
1169
, " import ModuleA as A (stuffB)"
1170
1170
, " main = print (stuffB .* stuffB)"
1171
1171
])
1172
- (Range (Position 3 17 ) (Position 3 18 ))
1172
+ (Range (Position 2 17 ) (Position 2 18 ))
1173
1173
[" Add (.*) to the import list of ModuleA" ]
1174
1174
(T. unlines
1175
1175
[ " module ModuleB where"
@@ -1206,7 +1206,7 @@ extendImportTests = testGroup "extend import actions"
1206
1206
, " b :: A"
1207
1207
, " b = Constructor"
1208
1208
])
1209
- (Range (Position 2 5 ) (Position 2 5 ))
1209
+ (Range (Position 3 5 ) (Position 3 5 ))
1210
1210
[" Add A(Constructor) to the import list of ModuleA" ]
1211
1211
(T. unlines
1212
1212
[ " module ModuleB where"
@@ -1225,7 +1225,7 @@ extendImportTests = testGroup "extend import actions"
1225
1225
, " b :: A"
1226
1226
, " b = Constructor"
1227
1227
])
1228
- (Range (Position 2 5 ) (Position 2 5 ))
1228
+ (Range (Position 3 5 ) (Position 3 5 ))
1229
1229
[" Add A(Constructor) to the import list of ModuleA" ]
1230
1230
(T. unlines
1231
1231
[ " module ModuleB where"
@@ -1245,7 +1245,7 @@ extendImportTests = testGroup "extend import actions"
1245
1245
, " b :: A"
1246
1246
, " b = ConstructorFoo"
1247
1247
])
1248
- (Range (Position 2 5 ) (Position 2 5 ))
1248
+ (Range (Position 3 5 ) (Position 3 5 ))
1249
1249
[" Add A(ConstructorFoo) to the import list of ModuleA" ]
1250
1250
(T. unlines
1251
1251
[ " module ModuleB where"
@@ -1266,7 +1266,7 @@ extendImportTests = testGroup "extend import actions"
1266
1266
, " import qualified ModuleA as A (stuffB)"
1267
1267
, " main = print (A.stuffA, A.stuffB)"
1268
1268
])
1269
- (Range (Position 3 17 ) (Position 3 18 ))
1269
+ (Range (Position 2 17 ) (Position 2 18 ))
1270
1270
[" Add stuffA to the import list of ModuleA" ]
1271
1271
(T. unlines
1272
1272
[ " module ModuleB where"
@@ -1682,9 +1682,7 @@ suggestImportDisambiguationTests = testGroup "suggest import disambiguation acti
1682
1682
doc <- openDoc file " haskell"
1683
1683
waitForProgressDone
1684
1684
void $ expectDiagnostics [(file, [(DsError , loc, " Ambiguous occurrence" ) | loc <- locs])]
1685
- contents <- documentContents doc
1686
- let range = Range (Position 0 0 ) (Position (length $ T. lines contents) 0 )
1687
- actions <- getCodeActions doc range
1685
+ actions <- getAllCodeActions doc
1688
1686
k doc actions
1689
1687
withHideFunction = withTarget (" HideFunction" <.> " hs" )
1690
1688
@@ -1891,7 +1889,7 @@ insertNewDefinitionTests = testGroup "insert new definition actions"
1891
1889
_ <- waitForDiagnostics
1892
1890
InR action@ CodeAction { _title = actionTitle } : _
1893
1891
<- sortOn (\ (InR CodeAction {_title= x}) -> x) <$>
1894
- getCodeActions docB (R 1 0 1 50 )
1892
+ getCodeActions docB (R 0 0 0 50 )
1895
1893
liftIO $ actionTitle @?= " Define select :: [Bool] -> Bool"
1896
1894
executeCodeAction action
1897
1895
contentAfterAction <- documentContents docB
@@ -1915,7 +1913,7 @@ insertNewDefinitionTests = testGroup "insert new definition actions"
1915
1913
_ <- waitForDiagnostics
1916
1914
InR action@ CodeAction { _title = actionTitle } : _
1917
1915
<- sortOn (\ (InR CodeAction {_title= x}) -> x) <$>
1918
- getCodeActions docB (R 1 0 1 50 )
1916
+ getCodeActions docB (R 0 0 0 50 )
1919
1917
liftIO $ actionTitle @?= " Define select :: [Bool] -> Bool"
1920
1918
executeCodeAction action
1921
1919
contentAfterAction <- documentContents docB
@@ -2063,15 +2061,15 @@ deleteUnusedDefinitionTests = testGroup "delete unused definition action"
2063
2061
docId <- createDoc " A.hs" " haskell" source
2064
2062
expectDiagnostics [ (" A.hs" , [(DsWarning , pos, " not used" )]) ]
2065
2063
2066
- (action, title) <- extractCodeAction docId " Delete"
2064
+ (action, title) <- extractCodeAction docId " Delete" pos
2067
2065
2068
2066
liftIO $ title @?= expectedTitle
2069
2067
executeCodeAction action
2070
2068
contentAfterAction <- documentContents docId
2071
2069
liftIO $ contentAfterAction @?= expectedResult
2072
2070
2073
- extractCodeAction docId actionPrefix = do
2074
- [action@ CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R 0 0 0 0 ) [actionPrefix]
2071
+ extractCodeAction docId actionPrefix (l, c) = do
2072
+ [action@ CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R l c l c ) [actionPrefix]
2075
2073
return (action, actionTitle)
2076
2074
2077
2075
addTypeAnnotationsToLiteralsTest :: TestTree
@@ -2196,15 +2194,16 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
2196
2194
docId <- createDoc " A.hs" " haskell" source
2197
2195
expectDiagnostics [ (" A.hs" , diag) ]
2198
2196
2199
- (action, title) <- extractCodeAction docId " Add type annotation"
2197
+ let cursors = map snd3 diag
2198
+ (action, title) <- extractCodeAction docId " Add type annotation" (minimum cursors) (maximum cursors)
2200
2199
2201
2200
liftIO $ title @?= expectedTitle
2202
2201
executeCodeAction action
2203
2202
contentAfterAction <- documentContents docId
2204
2203
liftIO $ contentAfterAction @?= expectedResult
2205
2204
2206
- extractCodeAction docId actionPrefix = do
2207
- [action@ CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R 0 0 0 0 ) [actionPrefix]
2205
+ extractCodeAction docId actionPrefix (l,c) (l', c') = do
2206
+ [action@ CodeAction { _title = actionTitle }] <- findCodeActionsByPrefix docId (R l c l' c' ) [actionPrefix]
2208
2207
return (action, actionTitle)
2209
2208
2210
2209
@@ -2250,7 +2249,7 @@ importRenameActionTests = testGroup "import rename actions"
2250
2249
]
2251
2250
doc <- createDoc " Testing.hs" " haskell" content
2252
2251
_ <- waitForDiagnostics
2253
- actionsOrCommands <- getCodeActions doc (Range (Position 2 8 ) (Position 2 16 ))
2252
+ actionsOrCommands <- getCodeActions doc (Range (Position 1 8 ) (Position 1 16 ))
2254
2253
let [changeToMap] = [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands, (" Data." <> modname) `T.isInfixOf` actionTitle ]
2255
2254
executeCodeAction changeToMap
2256
2255
contentAfterAction <- documentContents doc
@@ -2380,7 +2379,7 @@ addInstanceConstraintTests = let
2380
2379
check actionTitle originalCode expectedCode = testSession (T. unpack actionTitle) $ do
2381
2380
doc <- createDoc " Testing.hs" " haskell" originalCode
2382
2381
_ <- waitForDiagnostics
2383
- actionsOrCommands <- getCodeActions doc ( Range ( Position 6 0 ) ( Position 6 68 ))
2382
+ actionsOrCommands <- getAllCodeActions doc
2384
2383
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
2385
2384
executeCodeAction chosenAction
2386
2385
modifiedCode <- documentContents doc
@@ -2532,7 +2531,7 @@ checkCodeAction :: String -> T.Text -> T.Text -> T.Text -> TestTree
2532
2531
checkCodeAction testName actionTitle originalCode expectedCode = testSession testName $ do
2533
2532
doc <- createDoc " Testing.hs" " haskell" originalCode
2534
2533
_ <- waitForDiagnostics
2535
- actionsOrCommands <- getCodeActions doc ( Range ( Position 6 0 ) ( Position 6 maxBound ))
2534
+ actionsOrCommands <- getAllCodeActions doc
2536
2535
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
2537
2536
executeCodeAction chosenAction
2538
2537
modifiedCode <- documentContents doc
@@ -2615,7 +2614,7 @@ removeRedundantConstraintsTests = let
2615
2614
check actionTitle originalCode expectedCode = testSession (T. unpack actionTitle) $ do
2616
2615
doc <- createDoc " Testing.hs" " haskell" originalCode
2617
2616
_ <- waitForDiagnostics
2618
- actionsOrCommands <- getCodeActions doc ( Range ( Position 4 0 ) ( Position 4 maxBound ))
2617
+ actionsOrCommands <- getAllCodeActions doc
2619
2618
chosenAction <- liftIO $ pickActionWithTitle actionTitle actionsOrCommands
2620
2619
executeCodeAction chosenAction
2621
2620
modifiedCode <- documentContents doc
@@ -2625,7 +2624,7 @@ removeRedundantConstraintsTests = let
2625
2624
checkPeculiarFormatting title code = testSession title $ do
2626
2625
doc <- createDoc " Testing.hs" " haskell" code
2627
2626
_ <- waitForDiagnostics
2628
- actionsOrCommands <- getCodeActions doc ( Range ( Position 4 0 ) ( Position 4 maxBound ))
2627
+ actionsOrCommands <- getAllCodeActions doc
2629
2628
liftIO $ assertBool " Found some actions" (null actionsOrCommands)
2630
2629
2631
2630
in testGroup " remove redundant function constraints"
@@ -2769,7 +2768,7 @@ exportUnusedTests = testGroup "export unused actions"
2769
2768
, " ) where"
2770
2769
, " foo = id"
2771
2770
, " bar = foo" ])
2772
- (R 4 0 4 3 )
2771
+ (R 5 0 5 3 )
2773
2772
" Export ‘bar’"
2774
2773
(Just $ T. unlines
2775
2774
[ " {-# OPTIONS_GHC -Wunused-top-binds #-}"
0 commit comments