@@ -511,14 +511,8 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
511511 contents <- documentContents doc
512512
513513 let expected =
514- -- TODO: Why CPP???
515- #if __GLASGOW_HASKELL__ < 810
516514 [ " {-# LANGUAGE ScopedTypeVariables #-}"
517515 , " {-# LANGUAGE TypeApplications #-}"
518- #else
519- [ " {-# LANGUAGE TypeApplications #-}"
520- , " {-# LANGUAGE ScopedTypeVariables #-}"
521- #endif
522516 , " module TypeApplications where"
523517 , " "
524518 , " foo :: forall a. a -> a"
@@ -555,7 +549,7 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
555549 , " f Record{a, b} = a"
556550 ]
557551 liftIO $ T. lines contents @?= expected
558- , testCase " After Shebang " $ do
552+ , testCase " After shebang " $ do
559553 runSession hlsCommand fullCaps " test/testdata/addPragmas" $ do
560554 doc <- openDoc " AfterShebang.hs" " haskell"
561555
@@ -571,8 +565,8 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
571565 let expected =
572566 [ " #! /usr/bin/env nix-shell"
573567 , " #! nix-shell --pure -i runghc -p \" haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])\" "
574- , " "
575568 , " {-# LANGUAGE NamedFieldPuns #-}"
569+ , " "
576570 , " module AfterShebang where"
577571 , " "
578572 , " data Record = Record"
@@ -584,6 +578,67 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
584578 , " f Record{a, b} = a"
585579 ]
586580
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+
587642 liftIO $ T. lines contents @?= expected
588643 ]
589644
@@ -614,9 +669,9 @@ disableWarningTests =
614669 ]
615670 , T. unlines
616671 [ " {-# OPTIONS_GHC -Wall #-}"
672+ , " {-# OPTIONS_GHC -Wno-unused-imports #-}"
617673 , " "
618674 , " "
619- , " {-# OPTIONS_GHC -Wno-unused-imports #-}"
620675 , " module M where"
621676 , " "
622677 , " import Data.Functor"
0 commit comments