@@ -132,7 +132,7 @@ suggestAction packageExports ideOptions parsedModule text df annSource diag =
132
132
[ suggestSignature True diag
133
133
, rewrite df annSource $ \ _ ps -> suggestExtendImport packageExports ps diag
134
134
, rewrite df annSource $ \ df ps ->
135
- suggestImportDisambiguation df ps diag
135
+ suggestImportDisambiguation df text ps diag
136
136
, suggestFillTypeWildcard diag
137
137
, suggestFixConstructorImport text diag
138
138
, suggestModuleTypo diag
@@ -705,8 +705,12 @@ suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic{_range=_
705
705
, parent = Nothing
706
706
, isDatacon = False }
707
707
708
- data HidingMode = HideOthers [ModuleTarget ]
709
- | ToQualified ModuleName
708
+ data HidingMode
709
+ = HideOthers [ModuleTarget ]
710
+ | ToQualified
711
+ Bool
712
+ -- ^ Parenthesised?
713
+ ModuleName
710
714
deriving (Show )
711
715
712
716
data ModuleTarget
@@ -730,10 +734,11 @@ isPreludeImplicit = xopt Lang.ImplicitPrelude
730
734
-- | Suggests disambiguation for ambiguous symbols.
731
735
suggestImportDisambiguation ::
732
736
DynFlags ->
737
+ Maybe T. Text ->
733
738
ParsedSource ->
734
739
Diagnostic ->
735
740
[(T. Text , [Rewrite ])]
736
- suggestImportDisambiguation df ps@ (L _ HsModule {hsmodImports}) diag@ Diagnostic {.. }
741
+ suggestImportDisambiguation df ( Just txt) ps@ (L _ HsModule {hsmodImports}) diag@ Diagnostic {.. }
737
742
| Just [ambiguous] <-
738
743
matchRegexUnifySpaces
739
744
_message
@@ -759,7 +764,8 @@ suggestImportDisambiguation df ps@(L _ HsModule {hsmodImports}) diag@Diagnostic
759
764
= Just $ ImplicitPrelude $
760
765
maybe [] NE. toList (Map. lookup " Prelude" locDic)
761
766
toModuleTarget mName = ExistingImp <$> Map. lookup mName locDic
762
-
767
+ parensed =
768
+ " (" `T.isPrefixOf` T. strip (textInRange _range txt)
763
769
suggestions symbol mods
764
770
| Just targets <- mapM toModuleTarget mods =
765
771
sortOn fst
@@ -771,12 +777,12 @@ suggestImportDisambiguation df ps@(L _ HsModule {hsmodImports}) diag@Diagnostic
771
777
modNameText = T. pack $ moduleNameString modName
772
778
, mode <-
773
779
HideOthers restImports :
774
- [ ToQualified qual
780
+ [ ToQualified parensed qual
775
781
| ExistingImp imps <- [modTarget]
776
782
, L _ qual <- nubOrd $ mapMaybe (ideclAs . unLoc)
777
783
$ NE. toList imps
778
784
]
779
- ++ [ToQualified modName
785
+ ++ [ToQualified parensed modName
780
786
| any (occursUnqualified symbol . unLoc)
781
787
(targetImports modTarget)
782
788
|| case modTarget of
@@ -787,11 +793,12 @@ suggestImportDisambiguation df ps@(L _ HsModule {hsmodImports}) diag@Diagnostic
787
793
| otherwise = []
788
794
renderUniquify HideOthers {} modName symbol =
789
795
" Use " <> modName <> " for " <> symbol <> " , hiding other imports"
790
- renderUniquify (ToQualified qual) _ symbol =
796
+ renderUniquify (ToQualified _ qual) _ symbol =
791
797
" Replace with qualified: "
792
798
<> T. pack (moduleNameString qual)
793
799
<> " ."
794
800
<> symbol
801
+ suggestImportDisambiguation _ _ _ _ = []
795
802
796
803
occursUnqualified :: T. Text -> ImportDecl GhcPs -> Bool
797
804
occursUnqualified symbol ImportDecl {.. }
@@ -832,14 +839,18 @@ disambiguateSymbol pm Diagnostic {..} (T.unpack -> symbol) = \case
832
839
else hideSymbol symbol <$> imps
833
840
| ImplicitPrelude imps <- hiddens0
834
841
]
835
- (ToQualified qualMod) ->
842
+ (ToQualified parensed qualMod) ->
836
843
let occSym = mkVarOcc symbol
837
844
rdr = Qual qualMod occSym
838
- in [ Rewrite (rangeToSrcSpan " <dummy>" _range) $ \ df -> do
839
- liftParseAST @ (HsExpr GhcPs ) df $
845
+ in [ if parensed
846
+ then Rewrite (rangeToSrcSpan " <dummy>" _range) $ \ df ->
847
+ liftParseAST @ (HsExpr GhcPs ) df $
840
848
prettyPrint $
841
849
HsVar @ GhcPs noExtField $
842
850
L (UnhelpfulSpan " " ) rdr
851
+ else Rewrite (rangeToSrcSpan " <dummy>" _range) $ \ df ->
852
+ liftParseAST @ RdrName df $
853
+ prettyPrint $ L (UnhelpfulSpan " " ) rdr
843
854
]
844
855
845
856
findImportDeclByRange :: [LImportDecl GhcPs ] -> Range -> Maybe (LImportDecl GhcPs )
0 commit comments