diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs index f7b3b9824c..6b889d16d8 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs @@ -40,8 +40,10 @@ public async Task 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) { diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/FindReferencesFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/FindReferencesFacts.cs index 35d33d20d4..3f5a1707c4 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/FindReferencesFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/FindReferencesFacts.cs @@ -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() {