@@ -240,7 +240,8 @@ extendImportHandler' ideState ExtendImport {..}
240
240
extendImport (T. unpack <$> thingParent) (T. unpack newThing) (makeDeltaAst imp)
241
241
242
242
Nothing -> do
243
- let n = newImport importName sym importQual False (isPostQualifiedImport df)
243
+ let qns = (,) <$> importQual <*> Just (qualifiedImportStyle df)
244
+ n = newImport importName sym qns False
244
245
sym = if isNothing importQual then Just it else Nothing
245
246
it = case thingParent of
246
247
Nothing -> newThing
@@ -250,11 +251,6 @@ extendImportHandler' ideState ExtendImport {..}
250
251
| otherwise =
251
252
mzero
252
253
253
- isPostQualifiedImport :: DynFlags -> Bool
254
- isPostQualifiedImport df = hasImportQualifedPostEnabled && hasPrePositiveQualifiedWarning
255
- where hasImportQualifedPostEnabled = xopt ImportQualifiedPost df
256
- hasPrePositiveQualifiedWarning = wopt Opt_WarnPrepositiveQualifiedModule df
257
-
258
254
isWantedModule :: ModuleName -> Maybe ModuleName -> GenLocated l (ImportDecl GhcPs ) -> Bool
259
255
isWantedModule wantedModule Nothing (L _ it@ ImportDecl {ideclName, ideclHiding = Just (False , _)}) =
260
256
not (isQualifiedImport it) && unLoc ideclName == wantedModule
@@ -1435,16 +1431,17 @@ suggestNewImport df packageExportsMap ps fileContents Diagnostic{_message}
1435
1431
, Just (range, indent) <- newImportInsertRange ps fileContents
1436
1432
, extendImportSuggestions <- matchRegexUnifySpaces msg
1437
1433
" Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1438
- = let suggestions = nubSortBy simpleCompareImportSuggestion
1439
- (constructNewImportSuggestions df packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions) in
1434
+ = let qis = qualifiedImportStyle df
1435
+ suggestions = nubSortBy simpleCompareImportSuggestion
1436
+ (constructNewImportSuggestions packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions qis) in
1440
1437
map (\ (ImportSuggestion _ kind (unNewImport -> imp)) -> (imp, kind, TextEdit range (imp <> " \n " <> T. replicate indent " " ))) suggestions
1441
1438
where
1442
1439
L _ HsModule {.. } = astA ps
1443
1440
suggestNewImport _ _ _ _ _ = []
1444
1441
1445
1442
constructNewImportSuggestions
1446
- :: DynFlags -> ExportsMap -> (Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> [ImportSuggestion ]
1447
- constructNewImportSuggestions df exportsMap (qual, thingMissing) notTheseModules = nubOrdBy simpleCompareImportSuggestion
1443
+ :: ExportsMap -> (Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> QualifiedImportStyle -> [ImportSuggestion ]
1444
+ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules qis = nubOrdBy simpleCompareImportSuggestion
1448
1445
[ suggestion
1449
1446
| Just name <- [T. stripPrefix (maybe " " (<> " ." ) qual) $ notInScope thingMissing] -- strip away qualified module names from the unknown name
1450
1447
, identInfo <- maybe [] Set. toList $ (lookupOccEnv (getExportsMap exportsMap) (mkVarOrDataOcc name)) <> (lookupOccEnv (getExportsMap exportsMap) (mkTypeOcc name)) -- look up the modified unknown name in the export map
@@ -1456,7 +1453,7 @@ constructNewImportSuggestions df exportsMap (qual, thingMissing) notTheseModules
1456
1453
renderNewImport :: IdentInfo -> [ImportSuggestion ]
1457
1454
renderNewImport identInfo
1458
1455
| Just q <- qual
1459
- = [ImportSuggestion importanceScore (quickFixImportKind " new.qualified" ) (newQualImport m q $ isPostQualifiedImport df )]
1456
+ = [ImportSuggestion importanceScore (quickFixImportKind " new.qualified" ) (newQualImport m q qis )]
1460
1457
| otherwise
1461
1458
= [ImportSuggestion importanceScore (quickFixImportKind' " new" importStyle) (newUnqualImport m (renderImportStyle importStyle) False )
1462
1459
| importStyle <- NE. toList $ importStyles identInfo] ++
@@ -1634,11 +1631,10 @@ checkPragma name = check
1634
1631
newImport
1635
1632
:: T. Text -- ^ module name
1636
1633
-> Maybe T. Text -- ^ the symbol
1637
- -> Maybe T. Text -- ^ qualified name
1634
+ -> Maybe ( T. Text, QualifiedImportStyle ) -- ^ qualified name and style
1638
1635
-> Bool -- ^ the symbol is to be imported or hidden
1639
- -> Bool -- ^ the qualified name is to be imported in postfix position
1640
1636
-> NewImport
1641
- newImport modName mSymbol mQual hiding postfix = NewImport impStmt
1637
+ newImport modName mSymbol mQualNameStyle hiding = NewImport impStmt
1642
1638
where
1643
1639
symImp
1644
1640
| Just symbol <- mSymbol
@@ -1647,22 +1643,24 @@ newImport modName mSymbol mQual hiding postfix = NewImport impStmt
1647
1643
| otherwise = " "
1648
1644
impStmt =
1649
1645
" import "
1650
- <> qualifiedModName
1646
+ <> qualifiedModName ( snd <$> mQualNameStyle)
1651
1647
<> (if hiding then " hiding" else " " )
1652
1648
<> symImp
1653
1649
<> maybe " " (\ qual -> if modName == qual then " " else " as " <> qual) mQual
1654
- qualifiedModName | isJust mQual && postfix = modName <> " qualified"
1655
- | isJust mQual = " qualified " <> modName
1656
- | otherwise = " "
1650
+ mQual = fst <$> mQualNameStyle
1651
+ qualifiedModName Nothing = modName
1652
+ qualifiedModName (Just QualifiedImportPrefix ) = " qualified " <> modName
1653
+ qualifiedModName (Just QualifiedImportPostfix ) = modName <> " qualified"
1654
+
1657
1655
1658
- newQualImport :: T. Text -> T. Text -> Bool -> NewImport
1659
- newQualImport modName qual postfix = newImport modName Nothing (Just qual) False postfix
1656
+ newQualImport :: T. Text -> T. Text -> QualifiedImportStyle -> NewImport
1657
+ newQualImport modName qual qis = newImport modName Nothing (Just ( qual, qis)) False
1660
1658
1661
1659
newUnqualImport :: T. Text -> T. Text -> Bool -> NewImport
1662
- newUnqualImport modName symbol hiding = newImport modName (Just symbol) Nothing hiding False
1660
+ newUnqualImport modName symbol = newImport modName (Just symbol) Nothing
1663
1661
1664
1662
newImportAll :: T. Text -> NewImport
1665
- newImportAll modName = newImport modName Nothing Nothing False False
1663
+ newImportAll modName = newImport modName Nothing Nothing False
1666
1664
1667
1665
hideImplicitPreludeSymbol :: T. Text -> NewImport
1668
1666
hideImplicitPreludeSymbol symbol = newUnqualImport " Prelude" symbol True
0 commit comments