-
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
Update the Find-References feature to only find inheritance results that could lead to a specific member being used at runtime. #51637
Conversation
CancellationToken cancellationToken) | ||
{ | ||
// Static methods can't cascade. | ||
if (!symbol.IsStatic) |
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 is the meat of hte change. might be easier to read with whitespace changes off.
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/LinkedFileReferenceFinder.cs
Outdated
Show resolved
Hide resolved
…s/LinkedFileReferenceFinder.cs
src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesCascadeDirection.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchOptions.cs
Show resolved
Hide resolved
symbol, document, cancellationToken).ConfigureAwait(false)); | ||
var cascaded = await changeSignatureService.DetermineCascadedSymbolsFromDelegateInvokeAsync( | ||
symbol, document, cancellationToken).ConfigureAwait(false); | ||
result.AddRange(cascaded.SelectAsArray(s => (s, cascadeDirection))); |
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.
💡 The SelectAsArray
isn't helping here. It would be better to either use Select
, or an extension that allows AddRange
with a transformation argument.
src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchOptions.cs
Show resolved
Hide resolved
src/EditorFeatures/Test2/FindReferences/FindReferencesTests.WinmdSymbols.vb
Outdated
Show resolved
Hide resolved
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.
Auto-approval
Previously, 'Find References', which has both an programmatic API (FAR-API), and an end user facing feature (FAR-feature) would walk unilaterally through the inheritance hierarchy for a member with a particular. So, if you had:
Then doing a Find-References on D1.Foo, would find references to all three Foo methods shown there. This was non ideal if you consider this sort of case:
Here, this call to
Foo
can never, and will never call intoD1.Foo()
. Any call through it will never reach D1's Foo method. Contrast this with:Here,
c.Foo()
could call intoD1.Foo
ifc
is an instance ofD1
at runtime.The reason FAR-feature worked this way, is that it calls FAR-API to get the results. This FAR-API was designed for needs of consumers like
Rename
. InRename
, if you rename any of these three methods, then all have to be renamed as there is a coupling here between the members in terms of satisfying interface implementations. That coupling goes beyond what FAR-feature needs, but it caused the suboptimal behavior seen above.This change introduces a new concept to FAR-API where the client can specify if they want this behavior or not. Existing clients (like rename, or 3rd parties) will get the same results as before. However, clients (like FAR-feature, highlight-refs, and CodeLens) can opt into new behavior where we only find references that could actually call into that member at runtime.
This also has added benefits for performance as things like codelens (and FAR-feature, and highlight-refs) wont' cascade to many symbols that aren't needed when computing these results.