Fix finding references to operator overloads #1371
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, operator overloads have code lens, but number of references is always zero, and invoking findUsages directly (as in shift+f12) doesn't work either.
Roslyn returns references correctly, but FindUsagesService filters them out because "CanBeReferencedByName" is false. This filtering was previously ignored if method is constructor, and I 've added additional ignore for operators.
Added one test in FindUsagesFact for this case.
I think I saw that this filtering was added to go around some issue with get/set being returned as references to property, but I can't find that issue/PR.
Additional notes:
Implicit/explicit conversion has similar problem - codeLens with constant 0 references. Problem is, this appears to be downstream, it doesn't work in VS either and I couldn't make it to work here.
It would be nice if we could have find references to get/set, as in here Suggestion: Find-Refs on a setter should only find write-references to that property. dotnet/roslyn#17684. I see how to check if methodKind on invoked symbol is get or set, but I don't see a way to force SymbolFinder.FindReferencesAsync to return only read/write usages. Anyone has an idea?