From 2fdeb3d9da4861eb9ceec315d2a82a4b0e6226ca Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Wed, 3 Feb 2021 18:48:41 +0800 Subject: [PATCH] Don't extend the import list with child if the parent has already been imported as (..) --- .../src/Development/IDE/Plugin/CodeAction/ExactPrint.hs | 4 ++++ ghcide/test/exe/Main.hs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs index 762ba294c6..68198752c9 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs @@ -239,6 +239,8 @@ extendImportTopLevel _ _ _ = lift $ Left "Unable to extend the import list" -- extendImportViaParent "Bar" "Cons" AST: -- -- import A --> Error +-- import A (Bar(..)) --> Error +-- import A (Bar(Cons)) --> Error -- import A () --> import A (Bar(Cons)) -- import A (Foo, Bar) --> import A (Foo, Bar(Cons)) -- import A (Foo, Bar()) --> import A (Foo, Bar(Cons)) @@ -247,6 +249,8 @@ extendImportViaParent df parent child (L l it@ImportDecl {..}) | Just (hide, L l' lies) <- ideclHiding = go hide l' [] lies where go :: Bool -> SrcSpan -> [LIE GhcPs] -> [LIE GhcPs] -> TransformT (Either String) (LImportDecl GhcPs) + go _hide _l' _pre ((L _ll' (IEThingAll _ (L _ ie))) : _xs) + | parent == unIEWrappedName ie = lift . Left $ child <> " already included in " <> parent <> " imports" go hide l' pre (lAbs@(L ll' (IEThingAbs _ absIE@(L _ ie))) : xs) -- ThingAbs ie => ThingWith ie child | parent == unIEWrappedName ie = do diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index cf117b05c8..7472dea786 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -3669,11 +3669,17 @@ nonLocalCompletionTests = "ZeroPad" ["module A where", "import Text.Printf (FormatAdjustment (ZeroPad))", "ZeroPad"] , completionCommandTest - "parent imported" + "parent imported abs" ["module A where", "import Text.Printf (FormatAdjustment)", "ZeroPad"] (Position 2 4) "ZeroPad" ["module A where", "import Text.Printf (FormatAdjustment (ZeroPad))", "ZeroPad"] + , completionCommandTest + "parent imported all" + ["module A where", "import Text.Printf (FormatAdjustment (..))", "ZeroPad"] + (Position 2 4) + "ZeroPad" + ["module A where", "import Text.Printf (FormatAdjustment (..))", "ZeroPad"] , completionCommandTest "already imported" ["module A where", "import Text.Printf (FormatAdjustment (ZeroPad))", "ZeroPad"]