@@ -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,39 @@ 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 " import-list formats with brittany" $ runSession hieCommand fullCaps " test/testdata" $ do
169
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
170
+ _ <- waitForDiagnosticsSource " ghcmod"
171
+
172
+ actionsOrCommands <- getAllCodeActions doc
173
+ let _: action: _ = map fromAction actionsOrCommands
174
+ executeCodeAction action
175
+
176
+ contents <- getDocumentEdit doc
177
+ liftIO $ do
178
+ let l1: l2: l3: _ = T. lines contents
179
+ l1 `shouldBe` " import qualified Data.Maybe"
180
+ l2 `shouldBe` " import Control.Monad ( when )"
181
+ l3 `shouldBe` " main :: IO ()"
182
+ it " import-list formats with floskell" $ runSession hieCommand fullCaps " test/testdata" $ do
183
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
184
+ _ <- waitForDiagnosticsSource " ghcmod"
185
+
186
+ actionsOrCommands <- getAllCodeActions doc
187
+ let _: action: _ = map fromAction actionsOrCommands
188
+ executeCodeAction action
189
+
190
+ contents <- getDocumentEdit doc
191
+ liftIO $ do
192
+ let l1: l2: l3: _ = T. lines contents
193
+ l1 `shouldBe` " import qualified Data.Maybe"
194
+ l2 `shouldBe` " import Control.Monad (when)"
195
+ l3 `shouldBe` " main :: IO ()"
196
+ -- TODO: repeated code actions
166
197
it " respects format config" $ runSession hieCommand fullCaps " test/testdata" $ do
167
198
doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
168
199
_ <- waitForDiagnosticsSource " ghcmod"
@@ -179,7 +210,22 @@ spec = describe "code actions" $ do
179
210
let l1: l2: _ = T. lines contents
180
211
l1 `shouldBe` " import qualified Data.Maybe"
181
212
l2 `shouldBe` " import Control.Monad"
213
+ it " import-list respects format config" $ runSession hieCommand fullCaps " test/testdata" $ do
214
+ doc <- openDoc " CodeActionImportBrittany.hs" " haskell"
215
+ _ <- waitForDiagnosticsSource " ghcmod"
216
+
217
+ let config = def { formatOnImportOn = False }
218
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
182
219
220
+ actionsOrCommands <- getAllCodeActions doc
221
+ let _: action: _ = map fromAction actionsOrCommands
222
+ executeCodeAction action
223
+
224
+ contents <- getDocumentEdit doc
225
+ liftIO $ do
226
+ let l1: l2: _ = T. lines contents
227
+ l1 `shouldBe` " import qualified Data.Maybe"
228
+ l2 `shouldBe` " import Control.Monad (when)"
183
229
describe " add package suggestions" $ do
184
230
it " adds to .cabal files" $ runSession hieCommand fullCaps " test/testdata/addPackageTest/cabal" $ do
185
231
doc <- openDoc " AddPackage.hs" " haskell"
0 commit comments