@@ -104,6 +104,7 @@ import GHC (AddEpAnn (Ad
104
104
EpaLocation (.. ),
105
105
LEpaComment ,
106
106
LocatedA )
107
+ import qualified GHC.Data.EnumSet as ES
107
108
#else
108
109
import Language.Haskell.GHC.ExactPrint.Types (Annotation (annsDP ),
109
110
DeltaPos ,
@@ -243,7 +244,7 @@ extendImportHandler' ideState ExtendImport {..}
243
244
extendImport (T. unpack <$> thingParent) (T. unpack newThing) (makeDeltaAst imp)
244
245
245
246
Nothing -> do
246
- let n = newImport importName sym importQual False
247
+ let n = newImport importName sym importQual False (isPostQualifiedImport df)
247
248
sym = if isNothing importQual then Just it else Nothing
248
249
it = case thingParent of
249
250
Nothing -> newThing
@@ -253,6 +254,11 @@ extendImportHandler' ideState ExtendImport {..}
253
254
| otherwise =
254
255
mzero
255
256
257
+ isPostQualifiedImport :: DynFlags -> Bool
258
+ isPostQualifiedImport df = hasImportQualifedPostEnabled && hasPrePositiveQualifiedWarning
259
+ where hasImportQualifedPostEnabled = ES. member ImportQualifiedPost (extensionFlags df)
260
+ hasPrePositiveQualifiedWarning = ES. member Opt_WarnPrepositiveQualifiedModule (warningFlags df)
261
+
256
262
isWantedModule :: ModuleName -> Maybe ModuleName -> GenLocated l (ImportDecl GhcPs ) -> Bool
257
263
isWantedModule wantedModule Nothing (L _ it@ ImportDecl {ideclName, ideclHiding = Just (False , _)}) =
258
264
not (isQualifiedImport it) && unLoc ideclName == wantedModule
@@ -1639,8 +1645,9 @@ newImport
1639
1645
-> Maybe T. Text -- ^ the symbol
1640
1646
-> Maybe T. Text -- ^ qualified name
1641
1647
-> Bool -- ^ the symbol is to be imported or hidden
1648
+ -> Bool -- ^ the qualified name is to be imported in postfix position
1642
1649
-> NewImport
1643
- newImport modName mSymbol mQual hiding = NewImport impStmt
1650
+ newImport modName mSymbol mQual hiding postfix = NewImport impStmt
1644
1651
where
1645
1652
symImp
1646
1653
| Just symbol <- mSymbol
@@ -1649,20 +1656,22 @@ newImport modName mSymbol mQual hiding = NewImport impStmt
1649
1656
| otherwise = " "
1650
1657
impStmt =
1651
1658
" import "
1652
- <> maybe " " (const " qualified " ) mQual
1653
- <> modName
1659
+ <> qualifiedModName
1654
1660
<> (if hiding then " hiding" else " " )
1655
1661
<> symImp
1656
1662
<> maybe " " (\ qual -> if modName == qual then " " else " as " <> qual) mQual
1663
+ qualifiedModName | isJust mQual && postfix = modName <> " qualified"
1664
+ | isJust mQual = " qualified " <> modName
1665
+ | otherwise = " "
1657
1666
1658
1667
newQualImport :: T. Text -> T. Text -> NewImport
1659
- newQualImport modName qual = newImport modName Nothing (Just qual) False
1668
+ newQualImport modName qual = newImport modName Nothing (Just qual) False False
1660
1669
1661
1670
newUnqualImport :: T. Text -> T. Text -> Bool -> NewImport
1662
- newUnqualImport modName symbol = newImport modName (Just symbol) Nothing
1671
+ newUnqualImport modName symbol hiding = newImport modName (Just symbol) Nothing hiding False
1663
1672
1664
1673
newImportAll :: T. Text -> NewImport
1665
- newImportAll modName = newImport modName Nothing Nothing False
1674
+ newImportAll modName = newImport modName Nothing Nothing False False
1666
1675
1667
1676
hideImplicitPreludeSymbol :: T. Text -> NewImport
1668
1677
hideImplicitPreludeSymbol symbol = newUnqualImport " Prelude" symbol True
0 commit comments