@@ -136,15 +136,16 @@ spec = describe "code actions" $ do
136
136
let actns = map fromAction actionsOrCommands
137
137
138
138
liftIO $ do
139
- head actns ^. L. title `shouldBe` " Import module Control.Monad"
139
+ head actns ^. L. title `shouldBe` " Import module Control.Monad"
140
+ head (tail actns) ^. L. title `shouldBe` " Import module Control.Monad (when)"
140
141
forM_ actns $ \ a -> do
141
142
a ^. L. kind `shouldBe` Just CodeActionQuickFix
142
143
a ^. L. command `shouldSatisfy` isJust
143
144
a ^. L. edit `shouldBe` Nothing
144
145
let hasOneDiag (Just (List [_])) = True
145
146
hasOneDiag _ = False
146
147
a ^. L. diagnostics `shouldSatisfy` hasOneDiag
147
- length actns `shouldBe` 5
148
+ length actns `shouldBe` 10
148
149
149
150
executeCodeAction (head actns)
150
151
@@ -160,9 +161,59 @@ spec = describe "code actions" $ do
160
161
161
162
contents <- getDocumentEdit doc
162
163
liftIO $ do
163
- let l1: l2: _ = T. lines contents
164
+ let l1: l2: l3 : _ = T. lines contents
164
165
l1 `shouldBe` " import qualified Data.Maybe"
165
166
l2 `shouldBe` " import Control.Monad"
167
+ l3 `shouldBe` " main :: IO ()"
168
+ it " formats with floskell" $ runSession hieCommand fullCaps " test/testdata" $ do
169
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
170
+ _ <- waitForDiagnosticsSource " ghcmod"
171
+
172
+ let config = def { formattingProvider = " floskell" }
173
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
174
+
175
+ actionsOrCommands <- getAllCodeActions doc
176
+ let action: _ = map fromAction actionsOrCommands
177
+ executeCodeAction action
178
+
179
+ contents <- getDocumentEdit doc
180
+ liftIO $ do
181
+ let l1: l2: l3: _ = T. lines contents
182
+ l1 `shouldBe` " import qualified Data.Maybe"
183
+ l2 `shouldBe` " import Control.Monad"
184
+ l3 `shouldBe` " main :: IO ()"
185
+ it " import-list formats with brittany" $ runSession hieCommand fullCaps " test/testdata" $ do
186
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
187
+ _ <- waitForDiagnosticsSource " ghcmod"
188
+
189
+ actionsOrCommands <- getAllCodeActions doc
190
+ let _: action: _ = map fromAction actionsOrCommands
191
+ executeCodeAction action
192
+
193
+ contents <- getDocumentEdit doc
194
+ liftIO $ do
195
+ let l1: l2: l3: _ = T. lines contents
196
+ l1 `shouldBe` " import qualified Data.Maybe"
197
+ l2 `shouldBe` " import Control.Monad ( when )"
198
+ l3 `shouldBe` " main :: IO ()"
199
+ it " import-list formats with floskell" $ runSession hieCommand fullCaps " test/testdata" $ do
200
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
201
+ _ <- waitForDiagnosticsSource " ghcmod"
202
+
203
+ let config = def { formattingProvider = " floskell" }
204
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
205
+
206
+ actionsOrCommands <- getAllCodeActions doc
207
+ let _: action: _ = map fromAction actionsOrCommands
208
+ executeCodeAction action
209
+
210
+ contents <- getDocumentEdit doc
211
+ liftIO $ do
212
+ let l1: l2: l3: _ = T. lines contents
213
+ l1 `shouldBe` " import qualified Data.Maybe"
214
+ l2 `shouldBe` " import Control.Monad (when)"
215
+ l3 `shouldBe` " main :: IO ()"
216
+ -- TODO: repeated code actions
166
217
it " respects format config" $ runSession hieCommand fullCaps " test/testdata" $ do
167
218
doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
168
219
_ <- waitForDiagnosticsSource " ghcmod"
@@ -179,7 +230,22 @@ spec = describe "code actions" $ do
179
230
let l1: l2: _ = T. lines contents
180
231
l1 `shouldBe` " import qualified Data.Maybe"
181
232
l2 `shouldBe` " import Control.Monad"
233
+ it " import-list respects format config" $ runSession hieCommand fullCaps " test/testdata" $ do
234
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
235
+ _ <- waitForDiagnosticsSource " ghcmod"
236
+
237
+ let config = def { formatOnImportOn = False }
238
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
182
239
240
+ actionsOrCommands <- getAllCodeActions doc
241
+ let _: action: _ = map fromAction actionsOrCommands
242
+ executeCodeAction action
243
+
244
+ contents <- getDocumentEdit doc
245
+ liftIO $ do
246
+ let l1: l2: _ = T. lines contents
247
+ l1 `shouldBe` " import qualified Data.Maybe"
248
+ l2 `shouldBe` " import Control.Monad (when)"
183
249
describe " add package suggestions" $ do
184
250
it " adds to .cabal files" $ runSession hieCommand fullCaps " test/testdata/addPackageTest/cabal" $ do
185
251
doc <- openDoc " AddPackage.hs" " haskell"
0 commit comments