@@ -187,6 +187,7 @@ diagnosticTests = testGroup "diagnostics"
187187codeActionTests :: TestTree
188188codeActionTests = testGroup " code actions"
189189 [ renameActionTests
190+ , typeWildCardActionTests
190191 ]
191192
192193renameActionTests :: TestTree
@@ -265,6 +266,76 @@ renameActionTests = testGroup "rename actions"
265266 liftIO $ expectedContentAfterAction @=? contentAfterAction
266267 ]
267268
269+ typeWildCardActionTests :: TestTree
270+ typeWildCardActionTests = testGroup " type wildcard actions"
271+ [ testSession " global signature" $ do
272+ let content = T. unlines
273+ [ " module Testing where"
274+ , " func :: _"
275+ , " func x = x"
276+ ]
277+ doc <- openDoc' " Testing.hs" " haskell" content
278+ _ <- waitForDiagnostics
279+ actionsOrCommands <- getCodeActions doc (Range (Position 2 1 ) (Position 2 10 ))
280+ let [addSignature] = [action | CACodeAction action@ CodeAction { _title = actionTitle } <- actionsOrCommands
281+ , " Use type signature" `T.isInfixOf` actionTitle
282+ ]
283+ executeCodeAction addSignature
284+ contentAfterAction <- documentContents doc
285+ let expectedContentAfterAction = T. unlines
286+ [ " module Testing where"
287+ , " func :: (p -> p)"
288+ , " func x = x"
289+ ]
290+ liftIO $ expectedContentAfterAction @=? contentAfterAction
291+ , testSession " multi-line message" $ do
292+ let content = T. unlines
293+ [ " module Testing where"
294+ , " func :: _"
295+ , " func x y = x + y"
296+ ]
297+ doc <- openDoc' " Testing.hs" " haskell" content
298+ _ <- waitForDiagnostics
299+ actionsOrCommands <- getCodeActions doc (Range (Position 2 1 ) (Position 2 10 ))
300+ let [addSignature] = [action | CACodeAction action@ CodeAction { _title = actionTitle } <- actionsOrCommands
301+ , " Use type signature" `T.isInfixOf` actionTitle
302+ ]
303+ executeCodeAction addSignature
304+ contentAfterAction <- documentContents doc
305+ let expectedContentAfterAction = T. unlines
306+ [ " module Testing where"
307+ , " func :: (Integer -> Integer -> Integer)"
308+ , " func x y = x + y"
309+ ]
310+ liftIO $ expectedContentAfterAction @=? contentAfterAction
311+ , testSession " local signature" $ do
312+ let content = T. unlines
313+ [ " module Testing where"
314+ , " func :: Int -> Int"
315+ , " func x ="
316+ , " let y :: _"
317+ , " y = x * 2"
318+ , " in y"
319+ ]
320+ doc <- openDoc' " Testing.hs" " haskell" content
321+ _ <- waitForDiagnostics
322+ actionsOrCommands <- getCodeActions doc (Range (Position 4 1 ) (Position 4 10 ))
323+ let [addSignature] = [action | CACodeAction action@ CodeAction { _title = actionTitle } <- actionsOrCommands
324+ , " Use type signature" `T.isInfixOf` actionTitle
325+ ]
326+ executeCodeAction addSignature
327+ contentAfterAction <- documentContents doc
328+ let expectedContentAfterAction = T. unlines
329+ [ " module Testing where"
330+ , " func :: Int -> Int"
331+ , " func x ="
332+ , " let y :: (Int)"
333+ , " y = x * 2"
334+ , " in y"
335+ ]
336+ liftIO $ expectedContentAfterAction @=? contentAfterAction
337+ ]
338+
268339----------------------------------------------------------------------
269340-- Utils
270341
0 commit comments