diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs index 8dd95a0d770f5..8f4cbeab15a25 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs @@ -251,23 +251,18 @@ protected static async Task> GetIdentifierOrGlobalNa { return async (node, model) => { - var symbolInfoToMatch = FindReferenceCache.GetSymbolInfo(model, node, cancellationToken); + var symbolInfo = FindReferenceCache.GetSymbolInfo(model, node, cancellationToken); - var symbolToMatch = symbolInfoToMatch.Symbol; - var symbolToMatchCompilation = model.Compilation; - - if (await SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, symbolInfoToMatch.Symbol, cancellationToken).ConfigureAwait(false)) - { + if (await SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, symbolInfo.Symbol, cancellationToken).ConfigureAwait(false)) return (matched: true, CandidateReason.None); - } - else if (await symbolInfoToMatch.CandidateSymbols.AnyAsync(static (s, arg) => SymbolFinder.OriginalSymbolsMatchAsync(arg.solution, arg.searchSymbol, s, arg.cancellationToken), (solution, searchSymbol, cancellationToken)).ConfigureAwait(false)) - { - return (matched: true, symbolInfoToMatch.CandidateReason); - } - else + + foreach (var candidate in symbolInfo.CandidateSymbols) { - return (matched: false, CandidateReason.None); + if (await SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, candidate, cancellationToken).ConfigureAwait(false)) + return (matched: true, symbolInfo.CandidateReason); } + + return default; }; } @@ -471,11 +466,11 @@ protected static Task> FindDocumentsWithImplicitObjectC /// /// If the `node` implicitly matches the `symbol`, then it will be added to `locations`. /// - protected delegate void CollectMatchingReferences(ISymbol symbol, SyntaxNode node, - ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations); + protected delegate void CollectMatchingReferences( + SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations); protected static async Task> FindReferencesInDocumentAsync( - ISymbol symbol, + ISymbol _, Document document, Func isRelevantDocument, CollectMatchingReferences collectMatchingReferences, @@ -488,14 +483,12 @@ protected static async Task> FindReferencesInDocu var semanticFacts = document.GetRequiredLanguageService(); var syntaxRoot = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - using var _ = ArrayBuilder.GetInstance(out var locations); - - var originalUnreducedSymbolDefinition = symbol.GetOriginalUnreducedDefinition(); + using var _1 = ArrayBuilder.GetInstance(out var locations); foreach (var node in syntaxRoot.DescendantNodesAndSelf()) { cancellationToken.ThrowIfCancellationRequested(); - collectMatchingReferences(originalUnreducedSymbolDefinition, node, syntaxFacts, semanticFacts, locations); + collectMatchingReferences(node, syntaxFacts, semanticFacts, locations); } return locations.ToImmutable(); @@ -515,15 +508,15 @@ protected Task> FindReferencesInForEachStatements static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo) => syntaxTreeInfo.ContainsForEachStatement; - void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node, - ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) + void CollectMatchingReferences( + SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) { var info = semanticFacts.GetForEachSymbols(semanticModel, node); - if (Matches(info.GetEnumeratorMethod, originalUnreducedSymbolDefinition) || - Matches(info.MoveNextMethod, originalUnreducedSymbolDefinition) || - Matches(info.CurrentProperty, originalUnreducedSymbolDefinition) || - Matches(info.DisposeMethod, originalUnreducedSymbolDefinition)) + if (Matches(info.GetEnumeratorMethod, symbol) || + Matches(info.MoveNextMethod, symbol) || + Matches(info.CurrentProperty, symbol) || + Matches(info.DisposeMethod, symbol)) { var location = node.GetFirstToken().GetLocation(); var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken); @@ -551,8 +544,8 @@ protected Task> FindReferencesInDeconstructionAsy static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo) => syntaxTreeInfo.ContainsDeconstruction; - void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node, - ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) + void CollectMatchingReferences( + SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) { var deconstructMethods = semanticFacts.GetDeconstructionAssignmentMethods(semanticModel, node); if (deconstructMethods.IsEmpty) @@ -561,7 +554,7 @@ void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, Syntax deconstructMethods = semanticFacts.GetDeconstructionForEachMethods(semanticModel, node); } - if (deconstructMethods.Any(m => Matches(m, originalUnreducedSymbolDefinition))) + if (deconstructMethods.Any(m => Matches(m, symbol))) { var location = syntaxFacts.GetDeconstructionReferenceLocation(node); var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken); @@ -583,12 +576,12 @@ protected Task> FindReferencesInAwaitExpressionAs static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo) => syntaxTreeInfo.ContainsAwait; - void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node, - ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) + void CollectMatchingReferences( + SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) { var awaitExpressionMethod = semanticFacts.GetGetAwaiterMethod(semanticModel, node); - if (Matches(awaitExpressionMethod, originalUnreducedSymbolDefinition)) + if (Matches(awaitExpressionMethod, symbol)) { var location = node.GetFirstToken().GetLocation(); var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken); @@ -610,8 +603,8 @@ protected Task> FindReferencesInImplicitObjectCre static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo) => syntaxTreeInfo.ContainsImplicitObjectCreation; - void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node, - ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) + void CollectMatchingReferences( + SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) { if (!syntaxFacts.IsImplicitObjectCreation(node)) { @@ -621,7 +614,7 @@ void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, Syntax var constructor = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol; - if (Matches(constructor, originalUnreducedSymbolDefinition)) + if (Matches(constructor, symbol)) { var location = node.GetFirstToken().GetLocation(); var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken); @@ -632,11 +625,12 @@ void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, Syntax } } - protected static bool Matches(ISymbol? symbol1, ISymbol notNulloriginalUnreducedSymbol2) + protected static bool Matches(ISymbol? symbol1, ISymbol notNullOriginalUnreducedSymbol2) { + Contract.ThrowIfFalse(notNullOriginalUnreducedSymbol2.GetOriginalUnreducedDefinition().Equals(notNullOriginalUnreducedSymbol2)); return symbol1 != null && SymbolEquivalenceComparer.Instance.Equals( symbol1.GetOriginalUnreducedDefinition(), - notNulloriginalUnreducedSymbol2); + notNullOriginalUnreducedSymbol2); } protected static SymbolUsageInfo GetSymbolUsageInfo( diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs index ad85a41a807c9..992adf5d97b37 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs @@ -173,9 +173,7 @@ static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo) => syntaxTreeInfo.ContainsImplicitObjectCreation; void CollectMatchingReferences( - ISymbol originalUnreducedSymbolDefinition, SyntaxNode node, - ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, - ArrayBuilder locations) + SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) { if (!syntaxFacts.IsImplicitObjectCreationExpression(node)) return; @@ -190,7 +188,7 @@ void CollectMatchingReferences( return; var constructor = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol; - if (Matches(constructor, originalUnreducedSymbolDefinition)) + if (Matches(constructor, symbol)) { var location = node.GetFirstToken().GetLocation(); var symbolUsageInfo = GetSymbolUsageInfo(node, semanticModel, syntaxFacts, semanticFacts, cancellationToken);