Skip to content

Support find refs on global aliases.#56326

Merged
JoeRobich merged 17 commits intodotnet:mainfrom
CyrusNajmabadi:findRefsGlobalAlias
Sep 13, 2021
Merged

Support find refs on global aliases.#56326
JoeRobich merged 17 commits intodotnet:mainfrom
CyrusNajmabadi:findRefsGlobalAlias

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Sep 10, 2021

Fixes #55894

@ghost ghost added the Area-IDE label Sep 10, 2021
@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Support find refs on global aliases. Support find refs on global aliases. Sep 12, 2021
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review September 12, 2021 18:39
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner September 12, 2021 18:39
@@ -170,32 +170,47 @@ private async Task<HashSet<ProjectId>> GetProjectIdsToSearchAsync(

private async Task ProcessProjectAsync(Project project, ImmutableArray<ISymbol> allSymbols, CancellationToken cancellationToken)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the major top level algorithmic change. as we start to search a project, we first see if the symbols we're searching for could have global aliases to them in that project. We then pass those global aliases along to the actual 'finders' responsible for figuring out what doucments to search and what to search for in those documents.

protected static Task<ImmutableArray<FinderLocation>> FindAliasReferencesAsync(
ImmutableArray<FinderLocation> nonAliasReferences,
protected static Task<ImmutableArray<FinderLocation>> FindLocalAliasReferencesAsync(
ArrayBuilder<FinderLocation> initialReferences,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i stopped calling these 'nonAliasReferences' because these could be global aliases. I also renamed a lot of 'FindAliasXXX' helpers to 'FindLocalAliases' to help keep the split between global and local aliases clearer.

}

return result.ToImmutableAndClear();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the helper that actually tells you what global aliases there potentially are for a given symbol

namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal class ConstructorInitializerSymbolReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
internal sealed class ConstructorInitializerSymbolReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i sealed a lot of stuff for my sanity. it was harder to determine virtual/override routes otherwise.

HashSet<string>? globalAliases,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most finders were unaffected (except fort hese signature changes). the only finders that care are Namespaces/NamedTypes/Constructors

CancellationToken cancellationToken)
{
var documentsWithName = await FindDocumentsAsync(project, documents, cancellationToken, typeName).ConfigureAwait(false);
var documentsWithType = await FindDocumentsAsync(project, documents, symbol.ContainingType.SpecialType.ToPredefinedType(), cancellationToken).ConfigureAwait(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this got inlined into the caller. we don't want to search for built-in types twice, we only want to do the multi-passes for real names and aliases.

@JoeRobich JoeRobich disabled auto-merge September 13, 2021 22:26
@JoeRobich JoeRobich merged commit f857dca into dotnet:main Sep 13, 2021
@ghost ghost added this to the Next milestone Sep 13, 2021
@CyrusNajmabadi
Copy link
Contributor Author

Thanks!

@CyrusNajmabadi CyrusNajmabadi deleted the findRefsGlobalAlias branch September 13, 2021 22:27
@Cosifne Cosifne modified the milestones: Next, 17.0.P5 Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find all references for a "global" using alias finds alias references only in the file that defines it

4 participants