-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix find refs doing too much work lookign for types that had an alias to them in one file. #74015
Conversation
ref HashSet<(string alias, string name, int arity)>? globalAliasInfo, | ||
SyntaxNode node) | ||
{ | ||
if (!syntaxFacts.IsUsingAliasDirective(node)) | ||
return; | ||
|
||
syntaxFacts.GetPartsOfUsingAliasDirective(node, out var globalToken, out var alias, out var usingTarget); | ||
if (globalToken.IsMissing) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was the bug. IsMissing
is for when the parser thinks a token must be there but doesn't see it. e.g. if x == y)
will have a 'missing' open paren token. but if you just have using x = u;
there is no missing 'global' token there as that's just a legal using statement with a default global token.
this bug was making it so that every alias in the project was being treated as a global alias. We'd still only look for that alias if the name it bound to was hte name of hte symbol we were looking for. but this was still unnecessary work.
AddReferencesInDocumentWorker( | ||
methodSymbol, name, state, processResult, processResultData, cancellationToken); | ||
methodSymbol, containingTypeName, state, processResult, processResultData, cancellationToken); | ||
|
||
// Next, look for constructor references through a global alias to our containing type. | ||
foreach (var globalAlias in state.GlobalAliases) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we both want to search for references to global aliases anywhere that might be to our symbol, and...
methodSymbol, globalAlias, state, processResult, processResultData, cancellationToken); | ||
} | ||
foreach (var localAlias in state.Cache.SyntaxTreeIndex.GetAliases(containingTypeName, containingType.Arity)) | ||
FindReferenceToAlias(methodSymbol, state, processResult, processResultData, containingTypeName, localAlias, cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... we want to search for local aliases in this file alone to our symbol.
@@ -14,20 +14,20 @@ internal sealed partial class SyntaxTreeIndex : AbstractSyntaxIndex<SyntaxTreeIn | |||
private readonly LiteralInfo _literalInfo; | |||
private readonly IdentifierInfo _identifierInfo; | |||
private readonly ContextInfo _contextInfo; | |||
private readonly HashSet<(string alias, string name, int arity)>? _globalAliasInfo; | |||
private readonly HashSet<(string alias, string name, int arity, bool isGlobal)>? _aliasInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both the global and local alias info is useful to store per file. So we keep them both, with a flag saying which type it is.
{ | ||
globalAliasInfo = []; | ||
aliasInfo = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A silly bug was making it so that if there was a regular (non-global) using alias to a symbol anywhere in a project, that we would think there wa sa global alias to it. We'd then search for that global alias in all files to see if it was a hit for the original symbol, doing lots of unnecessary work.