@@ -511,14 +511,8 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
511
511
contents <- documentContents doc
512
512
513
513
let expected =
514
- -- TODO: Why CPP???
515
- #if __GLASGOW_HASKELL__ < 810
516
514
[ " {-# LANGUAGE ScopedTypeVariables #-}"
517
515
, " {-# LANGUAGE TypeApplications #-}"
518
- #else
519
- [ " {-# LANGUAGE TypeApplications #-}"
520
- , " {-# LANGUAGE ScopedTypeVariables #-}"
521
- #endif
522
516
, " module TypeApplications where"
523
517
, " "
524
518
, " foo :: forall a. a -> a"
@@ -555,7 +549,7 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
555
549
, " f Record{a, b} = a"
556
550
]
557
551
liftIO $ T. lines contents @?= expected
558
- , testCase " After Shebang " $ do
552
+ , testCase " After shebang " $ do
559
553
runSession hlsCommand fullCaps " test/testdata/addPragmas" $ do
560
554
doc <- openDoc " AfterShebang.hs" " haskell"
561
555
@@ -571,8 +565,8 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
571
565
let expected =
572
566
[ " #! /usr/bin/env nix-shell"
573
567
, " #! nix-shell --pure -i runghc -p \" haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])\" "
574
- , " "
575
568
, " {-# LANGUAGE NamedFieldPuns #-}"
569
+ , " "
576
570
, " module AfterShebang where"
577
571
, " "
578
572
, " data Record = Record"
@@ -584,6 +578,67 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
584
578
, " f Record{a, b} = a"
585
579
]
586
580
581
+ liftIO $ T. lines contents @?= expected
582
+ , testCase " Append to existing pragmas" $ do
583
+ runSession hlsCommand fullCaps " test/testdata/addPragmas" $ do
584
+ doc <- openDoc " AppendToExisting.hs" " haskell"
585
+
586
+ _ <- waitForDiagnosticsFrom doc
587
+ cas <- map fromAction <$> getAllCodeActions doc
588
+
589
+ liftIO $ " Add \" NamedFieldPuns\" " `elem` map (^. L. title) cas @? " Contains NamedFieldPuns code action"
590
+
591
+ executeCodeAction $ head cas
592
+
593
+ contents <- documentContents doc
594
+
595
+ let expected =
596
+ [ " -- | Doc before pragma"
597
+ , " {-# OPTIONS_GHC -Wno-dodgy-imports #-}"
598
+ , " {-# LANGUAGE NamedFieldPuns #-}"
599
+ , " module AppendToExisting where"
600
+ , " "
601
+ , " data Record = Record"
602
+ , " { a :: Int,"
603
+ , " b :: Double,"
604
+ , " c :: String"
605
+ , " }"
606
+ , " "
607
+ , " f Record{a, b} = a"
608
+ ]
609
+
610
+ liftIO $ T. lines contents @?= expected
611
+ , testCase " Before Doc Comments" $ do
612
+ runSession hlsCommand fullCaps " test/testdata/addPragmas" $ do
613
+ doc <- openDoc " BeforeDocComment.hs" " haskell"
614
+
615
+ _ <- waitForDiagnosticsFrom doc
616
+ cas <- map fromAction <$> getAllCodeActions doc
617
+
618
+ liftIO $ " Add \" NamedFieldPuns\" " `elem` map (^. L. title) cas @? " Contains NamedFieldPuns code action"
619
+
620
+ executeCodeAction $ head cas
621
+
622
+ contents <- documentContents doc
623
+
624
+ let expected =
625
+ [ " #! /usr/bin/env nix-shell"
626
+ , " #! nix-shell --pure -i runghc -p \" haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])\" "
627
+ , " {-# LANGUAGE NamedFieldPuns #-}"
628
+ , " -- | Doc Comment"
629
+ , " {- Block -}"
630
+ , " "
631
+ , " module BeforeDocComment where"
632
+ , " "
633
+ , " data Record = Record"
634
+ , " { a :: Int,"
635
+ , " b :: Double,"
636
+ , " c :: String"
637
+ , " }"
638
+ , " "
639
+ , " f Record{a, b} = a"
640
+ ]
641
+
587
642
liftIO $ T. lines contents @?= expected
588
643
]
589
644
@@ -614,9 +669,9 @@ disableWarningTests =
614
669
]
615
670
, T. unlines
616
671
[ " {-# OPTIONS_GHC -Wall #-}"
672
+ , " {-# OPTIONS_GHC -Wno-unused-imports #-}"
617
673
, " "
618
674
, " "
619
- , " {-# OPTIONS_GHC -Wno-unused-imports #-}"
620
675
, " module M where"
621
676
, " "
622
677
, " import Data.Functor"
0 commit comments