From 914a216798d2efa493717e63f2b8a71c6a4beab2 Mon Sep 17 00:00:00 2001 From: Ondrej Sebek Date: Sat, 21 May 2022 18:25:21 +0200 Subject: [PATCH] Test qualified completion - add test for post-qualified completion - add failing test for pre-qualified completion --- ghcide/test/exe/Main.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index d66fc30ca8f..d0a2e13af4c 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -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) @@ -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 @@ -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