Skip to content

Commit 4838b88

Browse files
committed
Test qualified completion
- add test for post-qualified completion - add failing test for pre-qualified completion - add failing test for multiline import
1 parent d983c89 commit 4838b88

File tree

1 file changed

+21
-5
lines changed
  • plugins/hls-refactor-plugin/test

1 file changed

+21
-5
lines changed

plugins/hls-refactor-plugin/test/Main.hs

+21-5
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ completionTests =
177177
"join"
178178
["{-# LANGUAGE NoImplicitPrelude #-}",
179179
"module A where", "import Control.Monad as M ()", "import Control.Monad as N (join)", "f = N.joi"]
180+
-- Regression test for https://github.com/haskell/haskell-language-server/issues/2824
181+
, completionNoCommandTest
182+
"explicit qualified"
183+
["{-# LANGUAGE NoImplicitPrelude #-}",
184+
"module A where", "import qualified Control.Monad as M (j)"]
185+
(Position 2 38)
186+
"join"
187+
, completionNoCommandTest
188+
"explicit qualified post"
189+
["{-# LANGUAGE NoImplicitPrelude, ImportQualifiedPost #-}",
190+
"module A where", "import Control.Monad qualified as M (j)"]
191+
(Position 2 38)
192+
"join"
193+
, completionNoCommandTest
194+
"multiline import"
195+
[ "{-# LANGUAGE NoImplicitPrelude #-}"
196+
, "module A where", "import Control.Monad", " (fore)"]
197+
(Position 3 9)
198+
"forever"
180199
]
181200
, testGroup "Data constructor"
182201
[ completionCommandTest
@@ -289,11 +308,8 @@ completionNoCommandTest name src pos wanted = testSession name $ do
289308
docId <- createDoc "A.hs" "haskell" (T.unlines src)
290309
_ <- waitForDiagnostics
291310
compls <- getCompletions docId pos
292-
let wantedC = find ( \case
293-
CompletionItem {_insertText = Just x} -> wanted `T.isPrefixOf` x
294-
_ -> False
295-
) compls
296-
case wantedC of
311+
let isPrefixOfInsertOrLabel ci = any (wanted `T.isPrefixOf`) [fromMaybe "" (ci ^. L.insertText), ci ^. L.label]
312+
case find isPrefixOfInsertOrLabel compls of
297313
Nothing ->
298314
liftIO $ assertFailure $ "Cannot find expected completion in: " <> show [_label | CompletionItem {_label} <- compls]
299315
Just CompletionItem{..} -> liftIO . assertBool ("Expected no command but got: " <> show _command) $ null _command

0 commit comments

Comments
 (0)