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