|
3 | 3 | {-# LANGUAGE DataKinds #-} |
4 | 4 | {-# LANGUAGE DuplicateRecordFields #-} |
5 | 5 | {-# LANGUAGE GADTs #-} |
| 6 | +{-# LANGUAGE LambdaCase #-} |
6 | 7 | {-# LANGUAGE OverloadedStrings #-} |
7 | 8 |
|
8 | 9 | module Test.AddArgument (tests) where |
9 | 10 |
|
| 11 | +import Data.List (find) |
| 12 | +import Data.Maybe (isJust) |
10 | 13 | import qualified Data.Text as T |
11 | 14 | import Development.IDE.Types.Location |
12 | 15 | import Language.LSP.Protocol.Types hiding |
@@ -42,7 +45,8 @@ tests = |
42 | 45 | mkGoldenAddArgTest "AddArgWithLambda" (r 1 0 1 50), |
43 | 46 | mkGoldenAddArgTest "MultiSigFirst" (r 2 0 2 50), |
44 | 47 | mkGoldenAddArgTest "MultiSigLast" (r 2 0 2 50), |
45 | | - mkGoldenAddArgTest "MultiSigMiddle" (r 2 0 2 50) |
| 48 | + mkGoldenAddArgTest "MultiSigMiddle" (r 2 0 2 50), |
| 49 | + mkNoAddArgForQualifiedNameTest |
46 | 50 | ] |
47 | 51 | where |
48 | 52 | r x y x' y' = Range (Position x y) (Position x' y') |
@@ -71,3 +75,30 @@ mkGoldenAddArgTest' testFileName range varName = do |
71 | 75 | "expected" |
72 | 76 | "hs" |
73 | 77 | action |
| 78 | + |
| 79 | +-- | Verify that the "Add argument" code action is NOT offered for qualified names (e.g. NE.toList). |
| 80 | +-- We also verify that an import suggestion IS offered, to confirm we're testing the right diagnostic. |
| 81 | +mkNoAddArgForQualifiedNameTest :: TestTree |
| 82 | +mkNoAddArgForQualifiedNameTest = |
| 83 | + testCase "No add argument for qualified names" $ runSessionWithServerInTmpDir def |
| 84 | + ( mkPluginTestDescriptor Refactor.iePluginDescriptor "ghcide-code-actions-imports-exports" |
| 85 | + <> mkPluginTestDescriptor Refactor.bindingsPluginDescriptor "ghcide-code-actions-bindings" |
| 86 | + ) |
| 87 | + (FS.mkVirtualFileTree "plugins/hls-refactor-plugin/test/data/add-arg" (FS.directProject "QualifiedName.hs")) |
| 88 | + $ do |
| 89 | + doc <- openDoc "QualifiedName.hs" "haskell" |
| 90 | + _ <- waitForDiagnostics |
| 91 | + actions <- getCodeActions doc (Range (Position 5 0) (Position 5 50)) |
| 92 | + -- Verify that an import suggestion exists, confirming the right diagnostic. |
| 93 | + let importAction = find (\case |
| 94 | + InR CodeAction {_title = t} -> "Data.List.NonEmpty" `T.isInfixOf` t |
| 95 | + _ -> False) actions |
| 96 | + liftIO $ assertBool |
| 97 | + "Expected an import suggestion code action for Data.List.NonEmpty" |
| 98 | + (isJust importAction) |
| 99 | + -- Verify that the "Add argument" code action is NOT offered |
| 100 | + let addArgAction = find (\case |
| 101 | + InR CodeAction {_title = t} -> "Add argument" `T.isPrefixOf` t |
| 102 | + _ -> False) actions |
| 103 | + liftIO $ addArgAction @?= Nothing |
| 104 | + |
0 commit comments