@@ -622,11 +622,8 @@ suggestExtendImport exportsMap contents Diagnostic{_range=_range,..}
622
622
importLine <- textInRange range c,
623
623
Just ident <- lookupExportMap binding mod ,
624
624
Just result <- addBindingToImportList ident importLine
625
- = [(" Add " <> renderImport ident <> " to the import list of " <> mod , [TextEdit range result])]
625
+ = [(" Add " <> renderIdentInfo ident <> " to the import list of " <> mod , [TextEdit range result])]
626
626
| otherwise = []
627
- renderImport IdentInfo {parent, rendered}
628
- | Just p <- parent = p <> " (" <> rendered <> " )"
629
- | otherwise = rendered
630
627
lookupExportMap binding mod
631
628
| Just match <- Map. lookup binding (getExportsMap exportsMap)
632
629
, [(ident, _)] <- filter (\ (_,m) -> mod == m) (Set. toList match)
@@ -899,7 +896,8 @@ removeRedundantConstraints mContents Diagnostic{..}
899
896
suggestNewImport :: ExportsMap -> ParsedModule -> Diagnostic -> [(T. Text , [TextEdit ])]
900
897
suggestNewImport packageExportsMap ParsedModule {pm_parsed_source = L _ HsModule {.. }} Diagnostic {_message}
901
898
| msg <- unifySpaces _message
902
- , Just name <- extractNotInScopeName msg
899
+ , Just thingMissing <- extractNotInScopeName msg
900
+ , qual <- extractQualifiedModuleName msg
903
901
, Just insertLine <- case hsmodImports of
904
902
[] -> case srcSpanStart $ getLoc (head hsmodDecls) of
905
903
RealSrcLoc s -> Just $ srcLocLine s - 1
@@ -911,15 +909,16 @@ suggestNewImport packageExportsMap ParsedModule {pm_parsed_source = L _ HsModule
911
909
, extendImportSuggestions <- matchRegexUnifySpaces msg
912
910
" Perhaps you want to add ‘[^’]*’ to the import list in the import of ‘([^’]*)’"
913
911
= [(imp, [TextEdit (Range insertPos insertPos) (imp <> " \n " )])
914
- | imp <- sort $ constructNewImportSuggestions packageExportsMap name extendImportSuggestions
912
+ | imp <- sort $ constructNewImportSuggestions packageExportsMap (qual, thingMissing) extendImportSuggestions
915
913
]
916
914
suggestNewImport _ _ _ = []
917
915
918
916
constructNewImportSuggestions
919
- :: ExportsMap -> NotInScope -> Maybe [T. Text ] -> [T. Text ]
920
- constructNewImportSuggestions exportsMap thingMissing notTheseModules = nubOrd
917
+ :: ExportsMap -> ( Maybe T. Text , NotInScope ) -> Maybe [T. Text ] -> [T. Text ]
918
+ constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules = nubOrd
921
919
[ suggestion
922
- | (identInfo, m) <- maybe [] Set. toList $ Map. lookup name (getExportsMap exportsMap)
920
+ | Just name <- [T. stripPrefix (maybe " " (<> " ." ) qual) $ notInScope thingMissing]
921
+ , (identInfo, m) <- maybe [] Set. toList $ Map. lookup name (getExportsMap exportsMap)
923
922
, canUseIdent thingMissing identInfo
924
923
, m `notElem` fromMaybe [] notTheseModules
925
924
, suggestion <- renderNewImport identInfo m
@@ -930,16 +929,9 @@ constructNewImportSuggestions exportsMap thingMissing notTheseModules = nubOrd
930
929
, asQ <- if q == m then " " else " as " <> q
931
930
= [" import qualified " <> m <> asQ]
932
931
| otherwise
933
- = [" import " <> m <> " (" <> importWhat identInfo <> " )"
932
+ = [" import " <> m <> " (" <> renderIdentInfo identInfo <> " )"
934
933
," import " <> m ]
935
934
936
- (qual, name) = case T. splitOn " ." (notInScope thingMissing) of
937
- [n] -> (Nothing , n)
938
- segments -> (Just (T. intercalate " ." $ init segments), last segments)
939
- importWhat IdentInfo {parent, rendered}
940
- | Just p <- parent = p <> " (" <> rendered <> " )"
941
- | otherwise = rendered
942
-
943
935
canUseIdent :: NotInScope -> IdentInfo -> Bool
944
936
canUseIdent NotInScopeDataConstructor {} = isDatacon
945
937
canUseIdent _ = const True
@@ -972,6 +964,13 @@ extractNotInScopeName x
972
964
| otherwise
973
965
= Nothing
974
966
967
+ extractQualifiedModuleName :: T. Text -> Maybe T. Text
968
+ extractQualifiedModuleName x
969
+ | Just [m] <- matchRegexUnifySpaces x " module named [^‘]*‘([^’]*)’"
970
+ = Just m
971
+ | otherwise
972
+ = Nothing
973
+
975
974
-------------------------------------------------------------------------------------------------
976
975
977
976
@@ -1171,3 +1170,8 @@ matchRegExMultipleImports message = do
1171
1170
_ -> Nothing
1172
1171
imps <- regExImports imports
1173
1172
return (binding, imps)
1173
+
1174
+ renderIdentInfo :: IdentInfo -> T. Text
1175
+ renderIdentInfo IdentInfo {parent, rendered}
1176
+ | Just p <- parent = p <> " (" <> rendered <> " )"
1177
+ | otherwise = rendered
0 commit comments