mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-02 08:53:07 +03:00
Add support for removing redundant qualified imports
This commit is contained in:
parent
fdefb6bc6d
commit
8d0e4a2ca0
@ -48,6 +48,7 @@ suggestAction contents Diagnostic{_range=_range@Range{..},..}
|
||||
-- except perhaps to import instances from `Data.List'
|
||||
-- To import instances alone, use: import Data.List()
|
||||
| "The import of " `T.isInfixOf` _message
|
||||
|| "The qualified import of " `T.isInfixOf` _message
|
||||
, " is redundant" `T.isInfixOf` _message
|
||||
= [("Remove import", [TextEdit (extendToWholeLineIfPossible contents _range) ""])]
|
||||
|
||||
|
@ -387,6 +387,30 @@ removeImportTests = testGroup "remove import actions"
|
||||
, "stuffB = 123"
|
||||
]
|
||||
liftIO $ expectedContentAfterAction @=? contentAfterAction
|
||||
, testSession "qualified redundant" $ do
|
||||
let contentA = T.unlines
|
||||
[ "module ModuleA where"
|
||||
]
|
||||
docA <- openDoc' "ModuleA.hs" "haskell" contentA
|
||||
let contentB = T.unlines
|
||||
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
|
||||
, "module ModuleB where"
|
||||
, "import qualified ModuleA"
|
||||
, "stuffB = 123"
|
||||
]
|
||||
docB <- openDoc' "ModuleB.hs" "haskell" contentB
|
||||
_ <- waitForDiagnostics
|
||||
[CACodeAction action@CodeAction { _title = actionTitle }]
|
||||
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
|
||||
liftIO $ "Remove import" @=? actionTitle
|
||||
executeCodeAction action
|
||||
contentAfterAction <- documentContents docB
|
||||
let expectedContentAfterAction = T.unlines
|
||||
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
|
||||
, "module ModuleB where"
|
||||
, "stuffB = 123"
|
||||
]
|
||||
liftIO $ expectedContentAfterAction @=? contentAfterAction
|
||||
]
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user