@@ -33,12 +33,15 @@ testPlugins = pluginDescToIdePlugins
33
33
, Ormolu. ormoluDescriptor " ormolu"
34
34
]
35
35
36
- brittanyFilePath :: FilePath
37
- brittanyFilePath = " test" </> " testdata" </> " CodeActionImportList.hs"
36
+ codeActionImportList :: FilePath
37
+ codeActionImportList = " test" </> " testdata" </> " CodeActionImportList.hs"
38
+
39
+ codeActionBigImportList :: FilePath
40
+ codeActionBigImportList = " test" </> " testdata" </> " CodeActionImportListElaborate.hs"
38
41
39
42
dispatchRequestP :: IdeGhcM a -> IO a
40
43
dispatchRequestP act = do
41
- cwd <- liftIO $ getCurrentDirectory
44
+ cwd <- liftIO getCurrentDirectory
42
45
runIGM testPlugins (cwd </> " test" </> " testdata" </> " File.hs" ) act
43
46
44
47
-- ---------------------------------------------------------------------
@@ -59,6 +62,26 @@ hsImportSpec = do
59
62
]
60
63
, [ TextEdit (Range (toPos (2 , 1 )) (toPos (2 , 1 ))) " import Data.Function ( ($) )\n "
61
64
]
65
+ , [ TextEdit (Range (toPos (2 , 1 )) (toPos (2 , 32 ))) $
66
+ " import System.IO ( IO\n " <>
67
+ " , hPutStrLn\n " <>
68
+ " )"
69
+ ]
70
+ , [ TextEdit (Range (toPos (3 , 1 )) (toPos (3 , 99 ))) $
71
+ " import Data.List ( find\n " <>
72
+ " , head\n " <>
73
+ " , last\n " <>
74
+ " , tail\n " <>
75
+ " , init\n " <>
76
+ " , union\n " <>
77
+ " , (\\\\ )\n " <>
78
+ " , null\n " <>
79
+ " , length\n " <>
80
+ " , cons\n " <>
81
+ " , uncons\n " <>
82
+ " , reverse\n " <>
83
+ " )"
84
+ ]
62
85
]
63
86
describe " formats with floskell" $ hsImportSpecRunner " floskell"
64
87
[ -- Expected output for simple format.
@@ -74,6 +97,12 @@ hsImportSpec = do
74
97
]
75
98
, [ TextEdit (Range (toPos (2 , 1 )) (toPos (2 , 1 ))) " import Data.Function (($))\n "
76
99
]
100
+ , [ TextEdit (Range (toPos (2 , 1 )) (toPos (2 , 32 ))) " import System.IO (IO, hPutStrLn)"
101
+ ]
102
+ , [ TextEdit (Range (toPos (3 , 1 )) (toPos (3 , 99 ))) $
103
+ " import Data.List (find, head, last, tail, init, union, (\\\\ ), null\n " <>
104
+ " , length, cons, uncons, reverse)"
105
+ ]
77
106
]
78
107
describe " formats with ormolu" $ case ghcVersion of
79
108
GHC86 -> hsImportSpecRunner " ormolu"
@@ -90,6 +119,10 @@ hsImportSpec = do
90
119
]
91
120
, [ TextEdit (Range (toPos (2 , 1 )) (toPos (2 , 1 ))) " import Data.Function (($))\n "
92
121
]
122
+ , [ TextEdit (Range (toPos (2 , 1 )) (toPos (2 , 32 ))) " import System.IO (IO, hPutStrLn)"
123
+ ]
124
+ , [ TextEdit (Range (toPos (3 , 1 )) (toPos (3 , 99 ))) " import Data.List ((\\\\ ), cons, find, head, init, last, length, null, reverse, tail, uncons, union)"
125
+ ]
93
126
]
94
127
_ -> it " is NOP formatter" $
95
128
pendingWith " Ormolu only supported by GHC >= 8.6. Need to restore this."
@@ -98,9 +131,9 @@ hsImportSpec = do
98
131
-- Parameterized HsImport Spec.
99
132
-- ---------------------------------------------------------------------
100
133
hsImportSpecRunner :: T. Text -> [[TextEdit ]] -> Spec
101
- hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
134
+ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6, e7, e8 ] = do
102
135
it " formats" $ do
103
- fp <- makeAbsolute brittanyFilePath
136
+ fp <- makeAbsolute codeActionImportList
104
137
let uri = filePathToUri fp
105
138
let act = importModule (ImportParams uri Simple " Control.Monad" )
106
139
@@ -110,7 +143,7 @@ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
110
143
Nothing -> fail " No Change found"
111
144
112
145
it " import-list formats" $ do
113
- fp <- makeAbsolute brittanyFilePath
146
+ fp <- makeAbsolute codeActionImportList
114
147
let uri = filePathToUri fp
115
148
let act = importModule (ImportParams uri (Complex (Import $ Only " when" )) " Control.Monad" )
116
149
@@ -120,7 +153,7 @@ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
120
153
Nothing -> fail " No Change found"
121
154
122
155
it " import-list type formats" $ do
123
- fp <- makeAbsolute brittanyFilePath
156
+ fp <- makeAbsolute codeActionImportList
124
157
let uri = filePathToUri fp
125
158
let act = importModule (ImportParams uri (Complex (Import $ Only " Maybe" )) " Data.Maybe" )
126
159
@@ -130,7 +163,7 @@ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
130
163
Nothing -> fail " No Change found"
131
164
132
165
it " import-list constructor formats" $ do
133
- fp <- makeAbsolute brittanyFilePath
166
+ fp <- makeAbsolute codeActionImportList
134
167
let uri = filePathToUri fp
135
168
let act = importModule (ImportParams uri (Complex (Import $ AllOf " Maybe" )) " Data.Maybe" )
136
169
@@ -140,7 +173,7 @@ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
140
173
Nothing -> fail " No Change found"
141
174
142
175
it " import-list constructor formats" $ do
143
- fp <- makeAbsolute brittanyFilePath
176
+ fp <- makeAbsolute codeActionImportList
144
177
let uri = filePathToUri fp
145
178
let act = importModule (ImportParams uri (Complex (Import $ OneOf " Maybe" " Nothing" )) " Data.Maybe" )
146
179
@@ -150,7 +183,7 @@ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
150
183
Nothing -> fail " No Change found"
151
184
152
185
it " import-list infix function formats" $ do
153
- fp <- makeAbsolute brittanyFilePath
186
+ fp <- makeAbsolute codeActionImportList
154
187
let uri = filePathToUri fp
155
188
let act = importModule (ImportParams uri (Complex (Import $ Only " $" )) " Data.Function" )
156
189
@@ -159,6 +192,27 @@ hsImportSpecRunner formatterName [e1, e2, e3, e4, e5, e6] = do
159
192
Just (List val) -> val `shouldBe` e6
160
193
Nothing -> fail " No Change found"
161
194
195
+ it " import-list with existing entry formats" $ do
196
+ fp <- makeAbsolute codeActionBigImportList
197
+ let uri = filePathToUri fp
198
+ let act = importModule (ImportParams uri (Complex (Import $ Only " hPutStrLn" )) " System.IO" )
199
+
200
+ IdeResultOk (WorkspaceEdit (Just changes) _) <- runSingle' (setFormatter formatterName) testPlugins fp act
201
+ case Map. lookup uri changes of
202
+ Just (List val) -> val `shouldBe` e7
203
+ Nothing -> fail " No Change found"
204
+
205
+ it " import-list with forced overflow formats" $ do
206
+ fp <- makeAbsolute codeActionBigImportList
207
+ let uri = filePathToUri fp
208
+ let act = importModule (ImportParams uri (Complex (Import $ Only " reverse" )) " Data.List" )
209
+
210
+ IdeResultOk (WorkspaceEdit (Just changes) _) <- runSingle' (setFormatter formatterName) testPlugins fp act
211
+ case Map. lookup uri changes of
212
+ Just (List val) -> val `shouldBe` e8
213
+ Nothing -> fail " No Change found"
214
+
215
+
162
216
-- Silence warnings
163
217
hsImportSpecRunner formatter args =
164
218
error $ " Not the right amount of arguments for \" hsImportSpec ("
0 commit comments