Skip to content

Commit 8d0e4a2

Browse files
committed
Add support for removing redundant qualified imports
1 parent fdefb6b commit 8d0e4a2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Development/IDE/LSP/CodeAction.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ suggestAction contents Diagnostic{_range=_range@Range{..},..}
4848
-- except perhaps to import instances from `Data.List'
4949
-- To import instances alone, use: import Data.List()
5050
| "The import of " `T.isInfixOf` _message
51+
|| "The qualified import of " `T.isInfixOf` _message
5152
, " is redundant" `T.isInfixOf` _message
5253
= [("Remove import", [TextEdit (extendToWholeLineIfPossible contents _range) ""])]
5354

test/exe/Main.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,30 @@ removeImportTests = testGroup "remove import actions"
387387
, "stuffB = 123"
388388
]
389389
liftIO $ expectedContentAfterAction @=? contentAfterAction
390+
, testSession "qualified redundant" $ do
391+
let contentA = T.unlines
392+
[ "module ModuleA where"
393+
]
394+
docA <- openDoc' "ModuleA.hs" "haskell" contentA
395+
let contentB = T.unlines
396+
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
397+
, "module ModuleB where"
398+
, "import qualified ModuleA"
399+
, "stuffB = 123"
400+
]
401+
docB <- openDoc' "ModuleB.hs" "haskell" contentB
402+
_ <- waitForDiagnostics
403+
[CACodeAction action@CodeAction { _title = actionTitle }]
404+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
405+
liftIO $ "Remove import" @=? actionTitle
406+
executeCodeAction action
407+
contentAfterAction <- documentContents docB
408+
let expectedContentAfterAction = T.unlines
409+
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
410+
, "module ModuleB where"
411+
, "stuffB = 123"
412+
]
413+
liftIO $ expectedContentAfterAction @=? contentAfterAction
390414
]
391415

392416
----------------------------------------------------------------------

0 commit comments

Comments
 (0)