1
1
2
- {-# LANGUAGE GADTs #-}
3
- {-# LANGUAGE OverloadedLabels #-}
2
+ {-# LANGUAGE GADTs #-}
3
+ {-# LANGUAGE LambdaCase #-}
4
+ {-# LANGUAGE OverloadedLabels #-}
5
+ {-# LANGUAGE OverloadedStrings #-}
6
+ {-# LANGUAGE RecordWildCards #-}
4
7
5
8
module CompletionTests (tests ) where
6
9
10
+ import Config
7
11
import Control.Lens ((^.) )
8
12
import qualified Control.Lens as Lens
9
13
import Control.Monad
@@ -14,7 +18,6 @@ import Data.Maybe
14
18
import Data.Row
15
19
import qualified Data.Text as T
16
20
import Development.IDE.GHC.Compat (GhcVersion (.. ), ghcVersion )
17
- import Development.IDE.Test (waitForTypecheck )
18
21
import Development.IDE.Types.Location
19
22
import Ide.Plugin.Config
20
23
import qualified Language.LSP.Protocol.Lens as L
@@ -25,10 +28,12 @@ import Language.LSP.Protocol.Types hiding
25
28
SemanticTokensEdit (.. ),
26
29
mkRange )
27
30
import Language.LSP.Test
28
- import System.FilePath
31
+ import Test.Hls (waitForTypecheck )
32
+ import qualified Test.Hls.FileSystem as FS
33
+ import Test.Hls.FileSystem (file , text )
34
+ import Test.Hls.Util (knownBrokenOnWindows )
29
35
import Test.Tasty
30
36
import Test.Tasty.HUnit
31
- import TestUtils
32
37
33
38
34
39
tests :: TestTree
44
49
, testGroup " doc" completionDocTests
45
50
]
46
51
52
+ testSessionEmpty :: TestName -> Session () -> TestTree
53
+ testSessionEmpty name = testCase name . runWithDummyPlugin (mkIdeTestFs [FS. directCradle [" A.hs" ]])
54
+
55
+ testSessionEmptyWithCradle :: TestName -> T. Text -> Session () -> TestTree
56
+ testSessionEmptyWithCradle name cradle = testCase name . runWithDummyPlugin (mkIdeTestFs [file " hie.yaml" (text cradle)])
57
+
58
+ testSessionSingleFile :: TestName -> FilePath -> T. Text -> Session () -> TestTree
59
+ testSessionSingleFile testName fp txt session =
60
+ testWithDummyPlugin testName (mkIdeTestFs [FS. directCradle [T. pack fp] , file fp (text txt)]) session
61
+
47
62
completionTest :: HasCallStack => String -> [T. Text ] -> Position -> [(T. Text , CompletionItemKind , T. Text , Bool , Bool , Maybe [TextEdit ])] -> TestTree
48
- completionTest name src pos expected = testSessionWait name $ do
49
- docId <- createDoc " A.hs" " haskell" ( T. unlines src)
63
+ completionTest name src pos expected = testSessionSingleFile name " A.hs " ( T. unlines src) $ do
64
+ docId <- openDoc " A.hs" " haskell"
50
65
_ <- waitForDiagnostics
51
66
compls <- getAndResolveCompletions docId pos
52
67
let compls' = [ (_label, _kind, _insertText, _additionalTextEdits) | CompletionItem {.. } <- compls]
@@ -185,7 +200,7 @@ localCompletionTests = [
185
200
[(" abcd" , CompletionItemKind_Function , " abcd" , True , False , Nothing )
186
201
,(" abcde" , CompletionItemKind_Function , " abcde" , True , False , Nothing )
187
202
],
188
- testSessionWait " incomplete entries" $ do
203
+ testSessionEmpty " incomplete entries" $ do
189
204
let src a = " data Data = " <> a
190
205
doc <- createDoc " A.hs" " haskell" $ src " AAA"
191
206
void $ waitForTypecheck doc
@@ -261,7 +276,7 @@ nonLocalCompletionTests =
261
276
[]
262
277
]
263
278
where
264
- brokenForWinGhc = knownBrokenFor ( BrokenSpecific Windows [ GHC92 , GHC94 , GHC96 , GHC98 ]) " Windows has strange things in scope for some reason"
279
+ brokenForWinGhc = knownBrokenOnWindows " Windows has strange things in scope for some reason"
265
280
266
281
otherCompletionTests :: [TestTree ]
267
282
otherCompletionTests = [
@@ -283,7 +298,7 @@ otherCompletionTests = [
283
298
(Position 3 11 )
284
299
[(" Integer" , CompletionItemKind_Struct , " Integer" , True , True , Nothing )],
285
300
286
- testSession " duplicate record fields" $ do
301
+ testSessionEmpty " duplicate record fields" $ do
287
302
void $
288
303
createDoc " B.hs" " haskell" $
289
304
T. unlines
@@ -304,22 +319,21 @@ otherCompletionTests = [
304
319
let compls' = [txt | CompletionItem {_insertText = Just txt, .. } <- compls, _label == " member" ]
305
320
liftIO $ take 1 compls' @?= [" member" ],
306
321
307
- testSessionWait " maxCompletions" $ do
322
+ testSessionEmpty " maxCompletions" $ do
308
323
doc <- createDoc " A.hs" " haskell" $ T. unlines
309
324
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
310
325
" module A () where" ,
311
326
" a = Prelude."
312
327
]
313
328
_ <- waitForDiagnostics
314
- compls <- getCompletions doc (Position 3 13 )
329
+ compls <- getCompletions doc (Position 3 13 )
315
330
liftIO $ length compls @?= maxCompletions def
316
331
]
317
332
318
333
packageCompletionTests :: [TestTree ]
319
334
packageCompletionTests =
320
- [ testSession' " fromList" $ \ dir -> do
321
- liftIO $ writeFile (dir </> " hie.yaml" )
322
- " cradle: {direct: {arguments: [-hide-all-packages, -package, base, A]}}"
335
+ [ testSessionEmptyWithCradle " fromList" " cradle: {direct: {arguments: [-hide-all-packages, -package, base, A]}}" $ do
336
+
323
337
doc <- createDoc " A.hs" " haskell" $ T. unlines
324
338
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
325
339
" module A () where" ,
@@ -337,9 +351,9 @@ packageCompletionTests =
337
351
map (" Defined in " <> ) (
338
352
[ " 'Data.List.NonEmpty"
339
353
, " 'GHC.Exts"
340
- ] ++ if ghcVersion >= GHC94 then [ " 'GHC.IsList" ] else [] )
354
+ ] ++ ([ " 'GHC.IsList" | ghcVersion >= GHC94 ]) )
341
355
342
- , testSessionWait " Map" $ do
356
+ , testSessionEmpty " Map" $ do
343
357
doc <- createDoc " A.hs" " haskell" $ T. unlines
344
358
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
345
359
" module A () where" ,
@@ -359,7 +373,7 @@ packageCompletionTests =
359
373
, " 'Data.Map.Lazy"
360
374
, " 'Data.Map.Strict"
361
375
]
362
- , testSessionWait " no duplicates" $ do
376
+ , testSessionEmpty " no duplicates" $ do
363
377
doc <- createDoc " A.hs" " haskell" $ T. unlines
364
378
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
365
379
" module A () where" ,
@@ -381,7 +395,7 @@ packageCompletionTests =
381
395
) compls
382
396
liftIO $ length duplicate @?= 1
383
397
384
- , testSessionWait " non-local before global" $ do
398
+ , testSessionEmpty " non-local before global" $ do
385
399
-- non local completions are more specific
386
400
doc <- createDoc " A.hs" " haskell" $ T. unlines
387
401
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
@@ -402,9 +416,7 @@ packageCompletionTests =
402
416
403
417
projectCompletionTests :: [TestTree ]
404
418
projectCompletionTests =
405
- [ testSession' " from hiedb" $ \ dir-> do
406
- liftIO $ writeFile (dir </> " hie.yaml" )
407
- " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}"
419
+ [ testSessionEmptyWithCradle " from hiedb" " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}" $ do
408
420
_ <- createDoc " A.hs" " haskell" $ T. unlines
409
421
[ " module A (anidentifier) where" ,
410
422
" anidentifier = ()"
@@ -423,9 +435,7 @@ projectCompletionTests =
423
435
, _label == " anidentifier"
424
436
]
425
437
liftIO $ compls' @?= [" Defined in 'A" ],
426
- testSession' " auto complete project imports" $ \ dir-> do
427
- liftIO $ writeFile (dir </> " hie.yaml" )
428
- " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" ALocalModule\" , \" B\" ]}}"
438
+ testSessionEmptyWithCradle " auto complete project imports" " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" ALocalModule\" , \" B\" ]}}" $ do
429
439
_ <- createDoc " ALocalModule.hs" " haskell" $ T. unlines
430
440
[ " module ALocalModule (anidentifier) where" ,
431
441
" anidentifier = ()"
@@ -440,9 +450,7 @@ projectCompletionTests =
440
450
let item = head $ filter ((== " ALocalModule" ) . (^. L. label)) compls
441
451
liftIO $ do
442
452
item ^. L. label @?= " ALocalModule" ,
443
- testSession' " auto complete functions from qualified imports without alias" $ \ dir-> do
444
- liftIO $ writeFile (dir </> " hie.yaml" )
445
- " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}"
453
+ testSessionEmptyWithCradle " auto complete functions from qualified imports without alias" " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}" $ do
446
454
_ <- createDoc " A.hs" " haskell" $ T. unlines
447
455
[ " module A (anidentifier) where" ,
448
456
" anidentifier = ()"
@@ -457,9 +465,8 @@ projectCompletionTests =
457
465
let item = head compls
458
466
liftIO $ do
459
467
item ^. L. label @?= " anidentifier" ,
460
- testSession' " auto complete functions from qualified imports with alias" $ \ dir-> do
461
- liftIO $ writeFile (dir </> " hie.yaml" )
462
- " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}"
468
+ testSessionEmptyWithCradle " auto complete functions from qualified imports with alias"
469
+ " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}" $ do
463
470
_ <- createDoc " A.hs" " haskell" $ T. unlines
464
471
[ " module A (anidentifier) where" ,
465
472
" anidentifier = ()"
@@ -478,30 +485,30 @@ projectCompletionTests =
478
485
479
486
completionDocTests :: [TestTree ]
480
487
completionDocTests =
481
- [ testSession " local define" $ do
488
+ [ testSessionEmpty " local define" $ do
482
489
doc <- createDoc " A.hs" " haskell" $ T. unlines
483
490
[ " module A where"
484
491
, " foo = ()"
485
492
, " bar = fo"
486
493
]
487
494
let expected = " *Defined at line 2, column 1 in this module*\n "
488
495
test doc (Position 2 8 ) " foo" Nothing [expected]
489
- , testSession " local empty doc" $ do
496
+ , testSessionEmpty " local empty doc" $ do
490
497
doc <- createDoc " A.hs" " haskell" $ T. unlines
491
498
[ " module A where"
492
499
, " foo = ()"
493
500
, " bar = fo"
494
501
]
495
502
test doc (Position 2 8 ) " foo" Nothing [" *Defined at line 2, column 1 in this module*\n " ]
496
- , testSession " local single line doc without newline" $ do
503
+ , testSessionEmpty " local single line doc without newline" $ do
497
504
doc <- createDoc " A.hs" " haskell" $ T. unlines
498
505
[ " module A where"
499
506
, " -- |docdoc"
500
507
, " foo = ()"
501
508
, " bar = fo"
502
509
]
503
510
test doc (Position 3 8 ) " foo" Nothing [" *Defined at line 3, column 1 in this module*\n * * *\n\n\n docdoc\n " ]
504
- , testSession " local multi line doc with newline" $ do
511
+ , testSessionEmpty " local multi line doc with newline" $ do
505
512
doc <- createDoc " A.hs" " haskell" $ T. unlines
506
513
[ " module A where"
507
514
, " -- | abcabc"
@@ -510,7 +517,7 @@ completionDocTests =
510
517
, " bar = fo"
511
518
]
512
519
test doc (Position 4 8 ) " foo" Nothing [" *Defined at line 4, column 1 in this module*\n * * *\n\n\n abcabc\n " ]
513
- , testSession " local multi line doc without newline" $ do
520
+ , testSessionEmpty " local multi line doc without newline" $ do
514
521
doc <- createDoc " A.hs" " haskell" $ T. unlines
515
522
[ " module A where"
516
523
, " -- | abcabc"
@@ -520,28 +527,28 @@ completionDocTests =
520
527
, " bar = fo"
521
528
]
522
529
test doc (Position 5 8 ) " foo" Nothing [" *Defined at line 5, column 1 in this module*\n * * *\n\n\n abcabc \n\n def\n " ]
523
- , testSession " extern empty doc" $ do
530
+ , testSessionEmpty " extern empty doc" $ do
524
531
doc <- createDoc " A.hs" " haskell" $ T. unlines
525
532
[ " module A where"
526
533
, " foo = od"
527
534
]
528
535
let expected = " *Imported from 'Prelude'*\n "
529
536
test doc (Position 1 8 ) " odd" (Just $ T. length expected) [expected]
530
- , brokenForMacGhc9 $ testSession " extern single line doc without '\\ n'" $ do
537
+ , testSessionEmpty " extern single line doc without '\\ n'" $ do
531
538
doc <- createDoc " A.hs" " haskell" $ T. unlines
532
539
[ " module A where"
533
540
, " foo = no"
534
541
]
535
542
let expected = " *Imported from 'Prelude'*\n * * *\n\n\n Boolean \" not\"\n "
536
543
test doc (Position 1 8 ) " not" (Just $ T. length expected) [expected]
537
- , brokenForMacGhc9 $ testSession " extern mulit line doc" $ do
544
+ , testSessionEmpty " extern mulit line doc" $ do
538
545
doc <- createDoc " A.hs" " haskell" $ T. unlines
539
546
[ " module A where"
540
547
, " foo = i"
541
548
]
542
549
let expected = " *Imported from 'Prelude'*\n * * *\n\n\n Identity function. \n ```haskell\n id x = x\n ```\n "
543
550
test doc (Position 1 7 ) " id" (Just $ T. length expected) [expected]
544
- , testSession " extern defined doc" $ do
551
+ , testSessionEmpty " extern defined doc" $ do
545
552
doc <- createDoc " A.hs" " haskell" $ T. unlines
546
553
[ " module A where"
547
554
, " foo = i"
@@ -550,8 +557,6 @@ completionDocTests =
550
557
test doc (Position 1 7 ) " id" (Just $ T. length expected) [expected]
551
558
]
552
559
where
553
- -- https://gitlab.haskell.org/ghc/ghc/-/issues/20903
554
- brokenForMacGhc9 = knownBrokenFor (BrokenSpecific MacOS [GHC92 , GHC94 , GHC96 ]) " Extern doc doesn't support MacOS for ghc9"
555
560
test doc pos label mn expected = do
556
561
_ <- waitForDiagnostics
557
562
compls <- getCompletions doc pos
0 commit comments