@@ -153,6 +153,25 @@ spec = describe "code actions" $ do
153
153
, " $ hPutStrLn stdout"
154
154
, " $ fromMaybe \" Good night, World!\" (Just \" Hello, World!\" )"
155
155
]
156
+ , -- Complex imports for Constructos and functions
157
+ [ " {-# LANGUAGE NoImplicitPrelude #-}"
158
+ , " import System.IO ( IO"
159
+ , " , hPutStrLn"
160
+ , " , stdout"
161
+ , " )"
162
+ , " import Prelude ( Bool(..) )"
163
+ , " import Control.Monad ( when )"
164
+ , " import Data.Maybe ( fromMaybe"
165
+ , " , Maybe(Just)"
166
+ , " )"
167
+ , " import Data.Function ( ($) )"
168
+ , " -- | Main entry point to the program"
169
+ , " main :: IO ()"
170
+ , " main ="
171
+ , " when True"
172
+ , " $ hPutStrLn stdout"
173
+ , " $ fromMaybe \" Good night, World!\" (Just \" Hello, World!\" )"
174
+ ]
156
175
]
157
176
hsImportSpec " floskell"
158
177
[ -- Expected output for simple format.
@@ -178,6 +197,20 @@ spec = describe "code actions" $ do
178
197
, " $ hPutStrLn stdout"
179
198
, " $ fromMaybe \" Good night, World!\" (Just \" Hello, World!\" )"
180
199
]
200
+ , -- Complex imports for Constructos and functions
201
+ [ " {-# LANGUAGE NoImplicitPrelude #-}"
202
+ , " import System.IO (IO, hPutStrLn, stdout)"
203
+ , " import Prelude (Bool(..))"
204
+ , " import Control.Monad (when)"
205
+ , " import Data.Maybe (fromMaybe, Maybe(Just))"
206
+ , " import Data.Function (($))"
207
+ , " -- | Main entry point to the program"
208
+ , " main :: IO ()"
209
+ , " main ="
210
+ , " when True"
211
+ , " $ hPutStrLn stdout"
212
+ , " $ fromMaybe \" Good night, World!\" (Just \" Hello, World!\" )"
213
+ ]
181
214
]
182
215
describe " add package suggestions" $ do
183
216
-- Only execute this test with ghc 8.4.4, below seems to be broken in the package.
@@ -504,7 +537,7 @@ spec = describe "code actions" $ do
504
537
-- Parameterized HsImport Spec.
505
538
-- ---------------------------------------------------------------------
506
539
hsImportSpec :: T. Text -> [[T. Text ]]-> Spec
507
- hsImportSpec formatterName [e1, e2, e3] =
540
+ hsImportSpec formatterName [e1, e2, e3, e4 ] =
508
541
describe (" Execute HsImport with formatter " <> T. unpack formatterName) $ do
509
542
it " works with 3.8 code action kinds" $ runSession hieCommand fullCaps " test/testdata" $ do
510
543
doc <- openDoc " CodeActionImport.hs" " haskell"
@@ -626,7 +659,7 @@ hsImportSpec formatterName [e1, e2, e3] =
626
659
l3 `shouldBe` " main :: IO ()"
627
660
l4 `shouldBe` " main = when True $ putStrLn \" hello\" "
628
661
629
- it ( " import-list respects format config with " <> T. unpack formatterName) $ runSession hieCommand fullCaps " test/testdata" $ do
662
+ it " import-list respects format config" $ runSession hieCommand fullCaps " test/testdata" $ do
630
663
doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
631
664
_ <- waitForDiagnosticsSource " ghcmod"
632
665
@@ -644,6 +677,63 @@ hsImportSpec formatterName [e1, e2, e3] =
644
677
l2 `shouldBe` " import Control.Monad (when)"
645
678
l3 `shouldBe` " main :: IO ()"
646
679
l4 `shouldBe` " main = when True $ putStrLn \" hello\" "
680
+
681
+ it " complex import-list" $ runSession hieCommand fullCaps " test/testdata" $ do
682
+ doc <- openDoc " CodeActionImportListElaborate.hs" " haskell"
683
+ _ <- waitForDiagnosticsSource " ghcmod"
684
+
685
+ let config = def { formatOnImportOn = False , formattingProvider = formatterName }
686
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
687
+
688
+ let wantedCodeActionTitles = [ " Import module System.IO (hPutSetrLn)"
689
+ , " Import module System.IO (stdout)"
690
+ , " Import module Control.Monad (when)"
691
+ , " Import module Data.Maybe (fromMaybe)"
692
+ , " Import module Data.Function (($))"
693
+ , " Import module Data.Maybe (Maybe(Just))"
694
+ , " Import module Prelude (Bool(..))"
695
+ ]
696
+
697
+ executeAllCodeActions doc wantedCodeActionTitles
698
+
699
+ contents <- getDocumentEdit doc
700
+ liftIO $
701
+ T. lines contents `shouldBe` e4
702
+
703
+ it " complex import-list respects format config" $ runSession hieCommand fullCaps " test/testdata" $ do
704
+ doc <- openDoc " CodeActionImportListElaborate.hs" " haskell"
705
+ _ <- waitForDiagnosticsSource " ghcmod"
706
+
707
+ let config = def { formatOnImportOn = False , formattingProvider = formatterName }
708
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
709
+
710
+ let wantedCodeActionTitles = [ " Import module System.IO (hPutStrLn)"
711
+ , " Import module System.IO (stdout)"
712
+ , " Import module Control.Monad (when)"
713
+ , " Import module Data.Maybe (fromMaybe)"
714
+ , " Import module Data.Function (($))"
715
+ , " Import module Data.Maybe (Maybe(Just))"
716
+ , " Import module Prelude (Bool(..))"
717
+ ]
718
+
719
+ executeAllCodeActions doc wantedCodeActionTitles
720
+
721
+ contents <- getDocumentEdit doc
722
+ liftIO $ do
723
+ let [l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12] = T. lines contents
724
+ l1 `shouldBe` " {-# LANGUAGE NoImplicitPrelude #-}"
725
+ l2 `shouldBe` " import System.IO (IO, hPutStrLn, stdout)"
726
+ l3 `shouldBe` " import Prelude (Bool(..))"
727
+ l4 `shouldBe` " import Control.Monad (when)"
728
+ l5 `shouldBe` " import Data.Maybe (fromMaybe, Maybe(Just))"
729
+ l6 `shouldBe` " import Data.Function (($))"
730
+ l7 `shouldBe` " -- | Main entry point to the program"
731
+ l8 `shouldBe` " main :: IO ()"
732
+ l9 `shouldBe` " main ="
733
+ l10 `shouldBe` " when True"
734
+ l11 `shouldBe` " $ hPutStrLn stdout"
735
+ l12 `shouldBe` " $ fromMaybe \" Good night, World!\" (Just \" Hello, World!\" )"
736
+
647
737
where
648
738
executeAllCodeActions :: TextDocumentIdentifier -> [T. Text ] -> Session ()
649
739
executeAllCodeActions doc names =
0 commit comments