Skip to content

Commit

Permalink
Test qualified completion
Browse files Browse the repository at this point in the history
- add test for post-qualified completion
- add failing test for pre-qualified completion
  • Loading branch information
xsebek committed May 21, 2022
1 parent eeb1d20 commit 914a216
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import Language.LSP.Types hiding
SemanticTokensEdit (_start),
mkRange)
import Language.LSP.Types.Capabilities
import qualified Language.LSP.Types.Lens as Lens (label)
import qualified Language.LSP.Types.Lens as Lens (label, insertText)
import qualified Language.LSP.Types.Lens as Lsp (diagnostics,
message,
params)
Expand Down Expand Up @@ -4781,11 +4781,8 @@ completionNoCommandTest name src pos wanted = testSession name $ do
docId <- createDoc "A.hs" "haskell" (T.unlines src)
_ <- waitForDiagnostics
compls <- getCompletions docId pos
let wantedC = find ( \case
CompletionItem {_insertText = Just x} -> wanted `T.isPrefixOf` x
_ -> False
) compls
case wantedC of
let isPrefixOfInsertOrLabel ci = any (wanted `T.isPrefixOf`) [fromMaybe "" (ci ^. Lens.insertText), ci ^. Lens.label]
case find isPrefixOfInsertOrLabel compls of
Nothing ->
liftIO $ assertFailure $ "Cannot find expected completion in: " <> show [_label | CompletionItem {_label} <- compls]
Just CompletionItem{..} -> liftIO . assertBool ("Expected no command but got: " <> show _command) $ null _command
Expand Down Expand Up @@ -5042,6 +5039,19 @@ nonLocalCompletionTests =
"join"
["{-# LANGUAGE NoImplicitPrelude #-}",
"module A where", "import Control.Monad as M ()", "import Control.Monad as N (join)", "f = N.joi"]
-- Failing test for https://github.com/haskell/haskell-language-server/issues/2824
, expectFailBecause "known broken #2824" $ completionNoCommandTest
"explicit qualified"
["{-# LANGUAGE NoImplicitPrelude #-}",
"module A where", "import qualified Control.Monad as M (j)"]
(Position 2 38)
"join"
, completionNoCommandTest
"explicit qualified post"
["{-# LANGUAGE NoImplicitPrelude, ImportQualifiedPost #-}",
"module A where", "import Control.Monad qualified as M (j)"]
(Position 2 38)
"join" -- TODO: Cannot find expected completion in: ["join"]
]
, testGroup "Data constructor"
[ completionCommandTest
Expand Down

0 comments on commit 914a216

Please sign in to comment.