@@ -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
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
@@ -1417,8 +1418,8 @@ suggestNewOrExtendImportForClassMethod packageExportsMap ps fileContents Diagnos
1417
1418
| otherwise -> []
1418
1419
where moduleText = moduleNameText identInfo
1419
1420
1420
- suggestNewImport :: ExportsMap -> Annotated ParsedSource -> T. Text -> Diagnostic -> [(T. Text , CodeActionKind , TextEdit )]
1421
- suggestNewImport packageExportsMap ps fileContents Diagnostic {_message}
1421
+ suggestNewImport :: DynFlags -> ExportsMap -> Annotated ParsedSource -> T. Text -> Diagnostic -> [(T. Text , CodeActionKind , TextEdit )]
1422
+ suggestNewImport df packageExportsMap ps fileContents Diagnostic {_message}
1422
1423
| msg <- unifySpaces _message
1423
1424
, Just thingMissing <- extractNotInScopeName msg
1424
1425
, qual <- extractQualifiedModuleName msg
@@ -1430,16 +1431,17 @@ suggestNewImport packageExportsMap ps fileContents Diagnostic{_message}
1430
1431
, Just (range, indent) <- newImportInsertRange ps fileContents
1431
1432
, extendImportSuggestions <- matchRegexUnifySpaces msg
1432
1433
" Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1433
- = let suggestions = nubSortBy simpleCompareImportSuggestion
1434
- (constructNewImportSuggestions packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions) in
1434
+ = let qis = qualifiedImportStyle df
1435
+ suggestions = nubSortBy simpleCompareImportSuggestion
1436
+ (constructNewImportSuggestions packageExportsMap (qual <|> qual', thingMissing) extendImportSuggestions qis) in
1435
1437
map (\ (ImportSuggestion _ kind (unNewImport -> imp)) -> (imp, kind, TextEdit range (imp <> " \n " <> T. replicate indent " " ))) suggestions
1436
1438
where
1437
1439
L _ HsModule {.. } = astA ps
1438
- suggestNewImport _ _ _ _ = []
1440
+ suggestNewImport _ _ _ _ _ = []
1439
1441
1440
1442
constructNewImportSuggestions
1441
- :: ExportsMap -> (Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> [ImportSuggestion ]
1442
- constructNewImportSuggestions 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
1443
1445
[ suggestion
1444
1446
| Just name <- [T. stripPrefix (maybe " " (<> " ." ) qual) $ notInScope thingMissing] -- strip away qualified module names from the unknown name
1445
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
@@ -1451,7 +1453,7 @@ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules =
1451
1453
renderNewImport :: IdentInfo -> [ImportSuggestion ]
1452
1454
renderNewImport identInfo
1453
1455
| Just q <- qual
1454
- = [ImportSuggestion importanceScore (quickFixImportKind " new.qualified" ) (newQualImport m q)]
1456
+ = [ImportSuggestion importanceScore (quickFixImportKind " new.qualified" ) (newQualImport m q qis )]
1455
1457
| otherwise
1456
1458
= [ImportSuggestion importanceScore (quickFixImportKind' " new" importStyle) (newUnqualImport m (renderImportStyle importStyle) False )
1457
1459
| importStyle <- NE. toList $ importStyles identInfo] ++
@@ -1629,10 +1631,10 @@ checkPragma name = check
1629
1631
newImport
1630
1632
:: T. Text -- ^ module name
1631
1633
-> Maybe T. Text -- ^ the symbol
1632
- -> Maybe T. Text -- ^ qualified name
1634
+ -> Maybe ( T. Text, QualifiedImportStyle ) -- ^ qualified name and style
1633
1635
-> Bool -- ^ the symbol is to be imported or hidden
1634
1636
-> NewImport
1635
- newImport modName mSymbol mQual hiding = NewImport impStmt
1637
+ newImport modName mSymbol mQualNameStyle hiding = NewImport impStmt
1636
1638
where
1637
1639
symImp
1638
1640
| Just symbol <- mSymbol
@@ -1641,14 +1643,18 @@ newImport modName mSymbol mQual hiding = NewImport impStmt
1641
1643
| otherwise = " "
1642
1644
impStmt =
1643
1645
" import "
1644
- <> maybe " " (const " qualified " ) mQual
1645
- <> modName
1646
+ <> qualifiedModName (snd <$> mQualNameStyle)
1646
1647
<> (if hiding then " hiding" else " " )
1647
1648
<> symImp
1648
1649
<> maybe " " (\ qual -> if modName == qual then " " else " as " <> qual) mQual
1650
+ mQual = fst <$> mQualNameStyle
1651
+ qualifiedModName Nothing = modName
1652
+ qualifiedModName (Just QualifiedImportPrefix ) = " qualified " <> modName
1653
+ qualifiedModName (Just QualifiedImportPostfix ) = modName <> " qualified"
1649
1654
1650
- newQualImport :: T. Text -> T. Text -> NewImport
1651
- newQualImport modName qual = newImport modName Nothing (Just qual) False
1655
+
1656
+ newQualImport :: T. Text -> T. Text -> QualifiedImportStyle -> NewImport
1657
+ newQualImport modName qual qis = newImport modName Nothing (Just (qual, qis)) False
1652
1658
1653
1659
newUnqualImport :: T. Text -> T. Text -> Bool -> NewImport
1654
1660
newUnqualImport modName symbol = newImport modName (Just symbol) Nothing
0 commit comments