Skip to content

Commit

Permalink
Merge pull request #1371 from SirIntruder/FindReferencesToOperatorOve…
Browse files Browse the repository at this point in the history
…rloads

Fix finding references to operator overloads
  • Loading branch information
Ravi Chande authored Jan 9, 2019
2 parents 4ccf6d9 + d403391 commit dd6eccd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public async Task<QuickFixResponse> Handle(FindUsagesRequest request)
var usages = request.OnlyThisFile
? await SymbolFinder.FindReferencesAsync(definition ?? symbol, _workspace.CurrentSolution, ImmutableHashSet.Create(document))
: await SymbolFinder.FindReferencesAsync(definition ?? symbol, _workspace.CurrentSolution);
var dontRequireReferenceByName = symbol is IMethodSymbol method &&
(method.MethodKind == MethodKind.Constructor || method.MethodKind == MethodKind.UserDefinedOperator);

foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || (symbol as IMethodSymbol)?.MethodKind == MethodKind.Constructor))
foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || dontRequireReferenceByName))
{
foreach (var location in usage.Locations)
{
Expand Down
30 changes: 30 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/FindReferencesFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,36 @@ public FooConsumer()
Assert.Equal(2, usages.QuickFixes.Count());
}

[Fact]
public async Task CanFindReferencesOfOperatorOverloads()
{
const string code = @"
public struct Vector2
{
public float x;
public float y;
public static Vector2 operator $$+(Vector2 lhs, Vector2 rhs) => new Vector2()
{
x = lhs.x + rhs.x,
y = lhs.y + rhs.y,
};
}
public class Vector2Consumer
{
public Vector2Consumer()
{
var a = new Vector2();
var b = new Vector2();
var c = a + b;
}
}";

var usages = await FindUsagesAsync(code);
Assert.Equal(2, usages.QuickFixes.Count());
}

[Fact]
public async Task LimitReferenceSearchToThisFile()
{
Expand Down

0 comments on commit dd6eccd

Please sign in to comment.