@@ -1195,6 +1195,11 @@ suggestNewImport packageExportsMap ParsedModule {pm_parsed_source = L _ HsModule
1195
1195
| msg <- unifySpaces _message
1196
1196
, Just thingMissing <- extractNotInScopeName msg
1197
1197
, qual <- extractQualifiedModuleName msg
1198
+ , qual' <-
1199
+ extractDoesNotExportModuleName msg
1200
+ >>= (findImportDeclByModuleName hsmodImports . T. unpack)
1201
+ >>= ideclAs . unLoc
1202
+ <&> T. pack . moduleNameString . unLoc
1198
1203
, Just insertLine <- case hsmodImports of
1199
1204
[] -> case srcSpanStart $ getLoc (head hsmodDecls) of
1200
1205
RealSrcLoc s -> Just $ srcLocLine s - 1
@@ -1206,7 +1211,7 @@ suggestNewImport packageExportsMap ParsedModule {pm_parsed_source = L _ HsModule
1206
1211
, extendImportSuggestions <- matchRegexUnifySpaces msg
1207
1212
" Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
1208
1213
= [(imp, [TextEdit (Range insertPos insertPos) (imp <> " \n " )])
1209
- | imp <- sort $ constructNewImportSuggestions packageExportsMap (qual, thingMissing) extendImportSuggestions
1214
+ | imp <- sort $ constructNewImportSuggestions packageExportsMap (qual <|> qual' , thingMissing) extendImportSuggestions
1210
1215
]
1211
1216
suggestNewImport _ _ _ = []
1212
1217
@@ -1272,6 +1277,37 @@ extractQualifiedModuleName x
1272
1277
| otherwise
1273
1278
= Nothing
1274
1279
1280
+ -- | If a module has been imported qualified, and we want to ues the same qualifier for other modules
1281
+ -- which haven't been imported, 'extractQualifiedModuleName' won't work. Thus we need extract the qualifier
1282
+ -- from the imported one.
1283
+ --
1284
+ -- For example, we write f = T.putStrLn, where putStrLn comes from Data.Text.IO, with the following import(s):
1285
+ -- 1.
1286
+ -- import qualified Data.Text as T
1287
+ --
1288
+ -- Module ‘Data.Text’ does not export ‘putStrLn’.
1289
+ --
1290
+ -- 2.
1291
+ -- import qualified Data.Text as T
1292
+ -- import qualified Data.Functor as T
1293
+ --
1294
+ -- Neither ‘Data.Functor’ nor ‘Data.Text’ exports ‘putStrLn’.
1295
+ --
1296
+ -- 3.
1297
+ -- import qualified Data.Text as T
1298
+ -- import qualified Data.Functor as T
1299
+ -- import qualified Data.Function as T
1300
+ --
1301
+ -- Neither ‘Data.Function’,
1302
+ -- ‘Data.Functor’ nor ‘Data.Text’ exports ‘putStrLn’.
1303
+ extractDoesNotExportModuleName :: T. Text -> Maybe T. Text
1304
+ extractDoesNotExportModuleName x
1305
+ | Just [m] <-
1306
+ matchRegexUnifySpaces x " Module ‘([^’]*)’ does not export"
1307
+ <|> matchRegexUnifySpaces x " nor ‘([^’]*)’ exports"
1308
+ = Just m
1309
+ | otherwise
1310
+ = Nothing
1275
1311
-------------------------------------------------------------------------------------------------
1276
1312
1277
1313
0 commit comments