Skip to content
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 finding references to operator overloads #1371

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,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