-
Notifications
You must be signed in to change notification settings - Fork 97
Add code action for remove all redundant imports #867
Conversation
Does it work? Can you add a test please? |
Any instruction of tests? I'm not sure what to add in |
All the tests live in test/exe/Main.hs |
removeImportTests :: TestTree
removeImportTests = testGroup "remove import actions"
[ testSession "redundant" $ do
let contentA = T.unlines
[ "module ModuleA where"
]
_docA <- createDoc "ModuleA.hs" "haskell" contentA
let contentB = T.unlines
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
, "module ModuleB where"
, "import ModuleA"
, "stuffB :: Integer"
, "stuffB = 123"
]
docB <- createDoc "ModuleB.hs" "haskell" contentB
_ <- waitForDiagnostics
-- two code actions are expected
-- one for remove the single redundant import in range, the other for remove all
[CACodeAction action@CodeAction { _title = actionTitle }]
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
liftIO $ "Remove import" @=? actionTitle
executeCodeAction action
-- the import has been removed so far...
contentAfterAction <- documentContents docB
let expectedContentAfterAction = T.unlines
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
, "module ModuleB where"
, "stuffB :: Integer"
, "stuffB = 123"
]
liftIO $ expectedContentAfterAction @=? contentAfterAction
, -- ......
|
Please create a separate test |
Ok. For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with some minor suggestions. Thank you for adding a test!
Thanks for the review and suggestions! I enum more cases in the test. |
Merged! Thanks again, this is an awesome contribution I've been wanting for a long time. |
* Add code action for remove all redundant imports * Call suggestRemoveRedundantImport only once * Adjust tests for code action removing all redundant imports * Update src/Development/IDE/Plugin/CodeAction.hs Co-authored-by: Pepe Iborra <[email protected]> * Refactor removeAll * Update the test of remove all redundant imports Co-authored-by: Pepe Iborra <[email protected]>
* Add code action for remove all redundant imports * Call suggestRemoveRedundantImport only once * Adjust tests for code action removing all redundant imports * Update src/Development/IDE/Plugin/CodeAction.hs Co-authored-by: Pepe Iborra <[email protected]> * Refactor removeAll * Update the test of remove all redundant imports Co-authored-by: Pepe Iborra <[email protected]>
* Add code action for remove all redundant imports * Call suggestRemoveRedundantImport only once * Adjust tests for code action removing all redundant imports * Update src/Development/IDE/Plugin/CodeAction.hs Co-authored-by: Pepe Iborra <[email protected]> * Refactor removeAll * Update the test of remove all redundant imports Co-authored-by: Pepe Iborra <[email protected]>
This PR implements haskell/haskell-language-server#339. The code removing single redundant import can be reused.