Skip to content

Commit 0460f99

Browse files
authored
Don't extend the import list with child if the parent has already been imported as (..) (#1302)
1 parent 8a91d03 commit 0460f99

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ extendImportTopLevel _ _ _ = lift $ Left "Unable to extend the import list"
239239
-- extendImportViaParent "Bar" "Cons" AST:
240240
--
241241
-- import A --> Error
242+
-- import A (Bar(..)) --> Error
243+
-- import A (Bar(Cons)) --> Error
242244
-- import A () --> import A (Bar(Cons))
243245
-- import A (Foo, Bar) --> import A (Foo, Bar(Cons))
244246
-- import A (Foo, Bar()) --> import A (Foo, Bar(Cons))
@@ -247,6 +249,8 @@ extendImportViaParent df parent child (L l it@ImportDecl {..})
247249
| Just (hide, L l' lies) <- ideclHiding = go hide l' [] lies
248250
where
249251
go :: Bool -> SrcSpan -> [LIE GhcPs] -> [LIE GhcPs] -> TransformT (Either String) (LImportDecl GhcPs)
252+
go _hide _l' _pre ((L _ll' (IEThingAll _ (L _ ie))) : _xs)
253+
| parent == unIEWrappedName ie = lift . Left $ child <> " already included in " <> parent <> " imports"
250254
go hide l' pre (lAbs@(L ll' (IEThingAbs _ absIE@(L _ ie))) : xs)
251255
-- ThingAbs ie => ThingWith ie child
252256
| parent == unIEWrappedName ie = do

ghcide/test/exe/Main.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3669,11 +3669,17 @@ nonLocalCompletionTests =
36693669
"ZeroPad"
36703670
["module A where", "import Text.Printf (FormatAdjustment (ZeroPad))", "ZeroPad"]
36713671
, completionCommandTest
3672-
"parent imported"
3672+
"parent imported abs"
36733673
["module A where", "import Text.Printf (FormatAdjustment)", "ZeroPad"]
36743674
(Position 2 4)
36753675
"ZeroPad"
36763676
["module A where", "import Text.Printf (FormatAdjustment (ZeroPad))", "ZeroPad"]
3677+
, completionCommandTest
3678+
"parent imported all"
3679+
["module A where", "import Text.Printf (FormatAdjustment (..))", "ZeroPad"]
3680+
(Position 2 4)
3681+
"ZeroPad"
3682+
["module A where", "import Text.Printf (FormatAdjustment (..))", "ZeroPad"]
36773683
, completionCommandTest
36783684
"already imported"
36793685
["module A where", "import Text.Printf (FormatAdjustment (ZeroPad))", "ZeroPad"]

0 commit comments

Comments
 (0)