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
@@ -14,7 +17,6 @@ import Data.Maybe
14
17
import Data.Row
15
18
import qualified Data.Text as T
16
19
import Development.IDE.GHC.Compat (GhcVersion (.. ), ghcVersion )
17
- import Development.IDE.Test (waitForTypecheck )
18
20
import Development.IDE.Types.Location
19
21
import Ide.Plugin.Config
20
22
import qualified Language.LSP.Protocol.Lens as L
@@ -26,9 +28,12 @@ import Language.LSP.Protocol.Types hiding
26
28
mkRange )
27
29
import Language.LSP.Test
28
30
import System.FilePath
31
+ import Test.Hls (waitForTypecheck )
32
+ import qualified Test.Hls.FileSystem as FS
33
+ import Test.Hls.FileSystem (file , text )
29
34
import Test.Tasty
30
35
import Test.Tasty.HUnit
31
- import TestUtils
36
+ import Util
32
37
33
38
34
39
tests :: TestTree
44
49
, testGroup " doc" completionDocTests
45
50
]
46
51
52
+ testSessionWithCorePluginEmpty :: TestName -> Session () -> TestTree
53
+ testSessionWithCorePluginEmpty name = testCase name . runSessionWithCorePluginEmpty [" A.hs" ]
54
+
55
+ testSessionWithCorePluginEmptyWithCradle :: TestName -> T. Text -> Session () -> TestTree
56
+ testSessionWithCorePluginEmptyWithCradle name cradle = testCase name . runSessionWithCorePlugin (mkFs [file " hie.yaml" (text cradle)])
57
+
47
58
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)
59
+ completionTest name src pos expected = testSessionWithCorePluginSingleFile name " A.hs " ( T. unlines src) $ do
60
+ docId <- openDoc " A.hs" " haskell"
50
61
_ <- waitForDiagnostics
51
62
compls <- getAndResolveCompletions docId pos
52
63
let compls' = [ (_label, _kind, _insertText, _additionalTextEdits) | CompletionItem {.. } <- compls]
@@ -185,7 +196,7 @@ localCompletionTests = [
185
196
[(" abcd" , CompletionItemKind_Function , " abcd" , True , False , Nothing )
186
197
,(" abcde" , CompletionItemKind_Function , " abcde" , True , False , Nothing )
187
198
],
188
- testSessionWait " incomplete entries" $ do
199
+ testSessionWithCorePluginEmpty " incomplete entries" $ do
189
200
let src a = " data Data = " <> a
190
201
doc <- createDoc " A.hs" " haskell" $ src " AAA"
191
202
void $ waitForTypecheck doc
@@ -283,7 +294,7 @@ otherCompletionTests = [
283
294
(Position 3 11 )
284
295
[(" Integer" , CompletionItemKind_Struct , " Integer" , True , True , Nothing )],
285
296
286
- testSession " duplicate record fields" $ do
297
+ testSessionWithCorePluginEmpty " duplicate record fields" $ do
287
298
void $
288
299
createDoc " B.hs" " haskell" $
289
300
T. unlines
@@ -304,22 +315,21 @@ otherCompletionTests = [
304
315
let compls' = [txt | CompletionItem {_insertText = Just txt, .. } <- compls, _label == " member" ]
305
316
liftIO $ take 1 compls' @?= [" member" ],
306
317
307
- testSessionWait " maxCompletions" $ do
318
+ testSessionWithCorePluginEmpty " maxCompletions" $ do
308
319
doc <- createDoc " A.hs" " haskell" $ T. unlines
309
320
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
310
321
" module A () where" ,
311
322
" a = Prelude."
312
323
]
313
324
_ <- waitForDiagnostics
314
- compls <- getCompletions doc (Position 3 13 )
325
+ compls <- getCompletions doc (Position 3 13 )
315
326
liftIO $ length compls @?= maxCompletions def
316
327
]
317
328
318
329
packageCompletionTests :: [TestTree ]
319
330
packageCompletionTests =
320
- [ testSession' " fromList" $ \ dir -> do
321
- liftIO $ writeFile (dir </> " hie.yaml" )
322
- " cradle: {direct: {arguments: [-hide-all-packages, -package, base, A]}}"
331
+ [ testSessionWithCorePluginEmptyWithCradle " fromList" " cradle: {direct: {arguments: [-hide-all-packages, -package, base, A]}}" $ do
332
+
323
333
doc <- createDoc " A.hs" " haskell" $ T. unlines
324
334
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
325
335
" module A () where" ,
@@ -339,7 +349,7 @@ packageCompletionTests =
339
349
, " 'GHC.Exts"
340
350
] ++ if ghcVersion >= GHC94 then [ " 'GHC.IsList" ] else [] )
341
351
342
- , testSessionWait " Map" $ do
352
+ , testSessionWithCorePluginEmpty " Map" $ do
343
353
doc <- createDoc " A.hs" " haskell" $ T. unlines
344
354
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
345
355
" module A () where" ,
@@ -359,7 +369,7 @@ packageCompletionTests =
359
369
, " 'Data.Map.Lazy"
360
370
, " 'Data.Map.Strict"
361
371
]
362
- , testSessionWait " no duplicates" $ do
372
+ , testSessionWithCorePluginEmpty " no duplicates" $ do
363
373
doc <- createDoc " A.hs" " haskell" $ T. unlines
364
374
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
365
375
" module A () where" ,
@@ -381,7 +391,7 @@ packageCompletionTests =
381
391
) compls
382
392
liftIO $ length duplicate @?= 1
383
393
384
- , testSessionWait " non-local before global" $ do
394
+ , testSessionWithCorePluginEmpty " non-local before global" $ do
385
395
-- non local completions are more specific
386
396
doc <- createDoc " A.hs" " haskell" $ T. unlines
387
397
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
@@ -402,9 +412,7 @@ packageCompletionTests =
402
412
403
413
projectCompletionTests :: [TestTree ]
404
414
projectCompletionTests =
405
- [ testSession' " from hiedb" $ \ dir-> do
406
- liftIO $ writeFile (dir </> " hie.yaml" )
407
- " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}"
415
+ [ testSessionWithCorePluginEmptyWithCradle " from hiedb" " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}" $ do
408
416
_ <- createDoc " A.hs" " haskell" $ T. unlines
409
417
[ " module A (anidentifier) where" ,
410
418
" anidentifier = ()"
@@ -423,9 +431,7 @@ projectCompletionTests =
423
431
, _label == " anidentifier"
424
432
]
425
433
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\" ]}}"
434
+ testSessionWithCorePluginEmptyWithCradle " auto complete project imports" " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" ALocalModule\" , \" B\" ]}}" $ do
429
435
_ <- createDoc " ALocalModule.hs" " haskell" $ T. unlines
430
436
[ " module ALocalModule (anidentifier) where" ,
431
437
" anidentifier = ()"
@@ -440,9 +446,7 @@ projectCompletionTests =
440
446
let item = head $ filter ((== " ALocalModule" ) . (^. L. label)) compls
441
447
liftIO $ do
442
448
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\" ]}}"
449
+ testSessionWithCorePluginEmptyWithCradle " auto complete functions from qualified imports without alias" " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}" $ do
446
450
_ <- createDoc " A.hs" " haskell" $ T. unlines
447
451
[ " module A (anidentifier) where" ,
448
452
" anidentifier = ()"
@@ -457,9 +461,8 @@ projectCompletionTests =
457
461
let item = head compls
458
462
liftIO $ do
459
463
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\" ]}}"
464
+ testSessionWithCorePluginEmptyWithCradle " auto complete functions from qualified imports with alias"
465
+ " cradle: {direct: {arguments: [\" -Wmissing-signatures\" , \" A\" , \" B\" ]}}" $ do
463
466
_ <- createDoc " A.hs" " haskell" $ T. unlines
464
467
[ " module A (anidentifier) where" ,
465
468
" anidentifier = ()"
@@ -478,30 +481,30 @@ projectCompletionTests =
478
481
479
482
completionDocTests :: [TestTree ]
480
483
completionDocTests =
481
- [ testSession " local define" $ do
484
+ [ testSessionWithCorePluginEmpty " local define" $ do
482
485
doc <- createDoc " A.hs" " haskell" $ T. unlines
483
486
[ " module A where"
484
487
, " foo = ()"
485
488
, " bar = fo"
486
489
]
487
490
let expected = " *Defined at line 2, column 1 in this module*\n "
488
491
test doc (Position 2 8 ) " foo" Nothing [expected]
489
- , testSession " local empty doc" $ do
492
+ , testSessionWithCorePluginEmpty " local empty doc" $ do
490
493
doc <- createDoc " A.hs" " haskell" $ T. unlines
491
494
[ " module A where"
492
495
, " foo = ()"
493
496
, " bar = fo"
494
497
]
495
498
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
499
+ , testSessionWithCorePluginEmpty " local single line doc without newline" $ do
497
500
doc <- createDoc " A.hs" " haskell" $ T. unlines
498
501
[ " module A where"
499
502
, " -- |docdoc"
500
503
, " foo = ()"
501
504
, " bar = fo"
502
505
]
503
506
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
507
+ , testSessionWithCorePluginEmpty " local multi line doc with newline" $ do
505
508
doc <- createDoc " A.hs" " haskell" $ T. unlines
506
509
[ " module A where"
507
510
, " -- | abcabc"
@@ -510,7 +513,7 @@ completionDocTests =
510
513
, " bar = fo"
511
514
]
512
515
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
516
+ , testSessionWithCorePluginEmpty " local multi line doc without newline" $ do
514
517
doc <- createDoc " A.hs" " haskell" $ T. unlines
515
518
[ " module A where"
516
519
, " -- | abcabc"
@@ -520,28 +523,28 @@ completionDocTests =
520
523
, " bar = fo"
521
524
]
522
525
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
526
+ , testSessionWithCorePluginEmpty " extern empty doc" $ do
524
527
doc <- createDoc " A.hs" " haskell" $ T. unlines
525
528
[ " module A where"
526
529
, " foo = od"
527
530
]
528
531
let expected = " *Imported from 'Prelude'*\n "
529
532
test doc (Position 1 8 ) " odd" (Just $ T. length expected) [expected]
530
- , brokenForMacGhc9 $ testSession " extern single line doc without '\\ n'" $ do
533
+ , brokenForMacGhc9 $ testSessionWithCorePluginEmpty " extern single line doc without '\\ n'" $ do
531
534
doc <- createDoc " A.hs" " haskell" $ T. unlines
532
535
[ " module A where"
533
536
, " foo = no"
534
537
]
535
538
let expected = " *Imported from 'Prelude'*\n * * *\n\n\n Boolean \" not\"\n "
536
539
test doc (Position 1 8 ) " not" (Just $ T. length expected) [expected]
537
- , brokenForMacGhc9 $ testSession " extern mulit line doc" $ do
540
+ , brokenForMacGhc9 $ testSessionWithCorePluginEmpty " extern mulit line doc" $ do
538
541
doc <- createDoc " A.hs" " haskell" $ T. unlines
539
542
[ " module A where"
540
543
, " foo = i"
541
544
]
542
545
let expected = " *Imported from 'Prelude'*\n * * *\n\n\n Identity function. \n ```haskell\n id x = x\n ```\n "
543
546
test doc (Position 1 7 ) " id" (Just $ T. length expected) [expected]
544
- , testSession " extern defined doc" $ do
547
+ , testSessionWithCorePluginEmpty " extern defined doc" $ do
545
548
doc <- createDoc " A.hs" " haskell" $ T. unlines
546
549
[ " module A where"
547
550
, " foo = i"
0 commit comments