Skip to content

Commit 73c55f8

Browse files
committed
Tests that code actions don't appear when Wingman is enabled
1 parent e1a10e0 commit 73c55f8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: hls-test-utils/src/Test/Hls/Util.hs

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Test.Hls.Util
1010
(
1111
codeActionSupportCaps
1212
, expectCodeAction
13+
, dontExpectCodeAction
1314
, expectDiagnostic
1415
, expectNoMoreDiagnostics
1516
, expectSameLocations
@@ -45,6 +46,7 @@ import Control.Lens ((^.))
4546
import Control.Monad
4647
import Control.Monad.IO.Class
4748
import qualified Data.Aeson as A
49+
import Data.Bool (bool)
4850
import Data.Default
4951
import Data.List (intercalate)
5052
import Data.List.Extra (find)
@@ -315,6 +317,10 @@ fromCommand _ = error "Not a command"
315317
onMatch :: [a] -> (a -> Bool) -> String -> IO a
316318
onMatch as predicate err = maybe (fail err) return (find predicate as)
317319

320+
noMatch :: [a] -> (a -> Bool) -> String -> IO ()
321+
noMatch [] _ _ = pure ()
322+
noMatch as predicate err = bool (pure ()) (fail err) (any predicate as)
323+
318324
inspectDiagnostic :: [Diagnostic] -> [T.Text] -> IO Diagnostic
319325
inspectDiagnostic diags s = onMatch diags (\ca -> all (`T.isInfixOf` (ca ^. L.message)) s) err
320326
where err = "expected diagnostic matching '" ++ show s ++ "' but did not find one"
@@ -331,6 +337,14 @@ inspectCodeAction cars s = fromAction <$> onMatch cars predicate err
331337
expectCodeAction :: [Command |? CodeAction] -> [T.Text] -> IO ()
332338
expectCodeAction cars s = void $ inspectCodeAction cars s
333339

340+
dontExpectCodeAction :: [Command |? CodeAction] -> [T.Text] -> IO ()
341+
dontExpectCodeAction cars s =
342+
noMatch cars predicate err
343+
where predicate (InR ca) = all (`T.isInfixOf` (ca ^. L.title)) s
344+
predicate _ = False
345+
err = "expected code action matching '" ++ show s ++ "' but did not find one"
346+
347+
334348
inspectCommand :: [Command |? CodeAction] -> [T.Text] -> IO Command
335349
inspectCommand cars s = fromCommand <$> onMatch cars predicate err
336350
where predicate (InL command) = all (`T.isInfixOf` (command ^. L.title)) s

Diff for: test/functional/FunctionalCodeAction.hs

+19
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,15 @@ typedHoleTests = testGroup "typed hole code actions" [
422422
, "foo x = maxBound"
423423
]
424424

425+
, testCase "doesn't work when wingman is active" $
426+
runSession hlsCommand fullCaps "test/testdata" $ do
427+
doc <- openDoc "TypedHoles.hs" "haskell"
428+
_ <- waitForDiagnosticsFromSource doc "typecheck"
429+
cas <- getAllCodeActions doc
430+
liftIO $ do
431+
dontExpectCodeAction cas ["replace _ with minBound"]
432+
dontExpectCodeAction cas ["replace _ with foo _"]
433+
425434
, testCase "shows more suggestions" $
426435
runSession hlsCommand fullCaps "test/testdata" $ do
427436
disableWingman
@@ -446,6 +455,16 @@ typedHoleTests = testGroup "typed hole code actions" [
446455
, " where"
447456
, " stuff (A a) = A (a + 1)"
448457
]
458+
459+
, testCase "doesnt show more suggestions when wingman is active" $
460+
runSession hlsCommand fullCaps "test/testdata" $ do
461+
doc <- openDoc "TypedHoles2.hs" "haskell"
462+
_ <- waitForDiagnosticsFromSource doc "typecheck"
463+
cas <- getAllCodeActions doc
464+
465+
liftIO $ do
466+
dontExpectCodeAction cas ["replace _ with foo2 _"]
467+
dontExpectCodeAction cas ["replace _ with A _"]
449468
]
450469

451470
signatureTests :: TestTree

0 commit comments

Comments
 (0)