From e8e2d9a7ca487a359e6b8047d3f3b622063b6d6c Mon Sep 17 00:00:00 2001 From: MisaJovanovic Date: Thu, 27 Dec 2018 17:42:12 +0100 Subject: [PATCH 1/3] CanFindReferencesOfOperatorOverloads --- .../Services/Navigation/FindUsagesService.cs | 4 ++- .../FindReferencesFacts.cs | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs index 0107a6650c..e00a67b7a1 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs @@ -39,8 +39,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 alwaysIncludeAllUsages = 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 || alwaysIncludeAllUsages)) { 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() { From 931f7cef81314665852c9bd8cb8a5f755ddace33 Mon Sep 17 00:00:00 2001 From: MisaJovanovic Date: Thu, 27 Dec 2018 18:28:11 +0100 Subject: [PATCH 2/3] better name --- .../Services/Navigation/FindUsagesService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs index e00a67b7a1..f8f4b3a2e1 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs @@ -39,10 +39,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 alwaysIncludeAllUsages = symbol is IMethodSymbol method && + var ignoreCanBeReferencedByName = symbol is IMethodSymbol method && (method.MethodKind == MethodKind.Constructor || method.MethodKind == MethodKind.UserDefinedOperator); - foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || alwaysIncludeAllUsages)) + foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || ignoreCanBeReferencedByName)) { foreach (var location in usage.Locations) { From 32c15f78f2120091c09c8602b6a64a3e0e3e9a40 Mon Sep 17 00:00:00 2001 From: MisaJovanovic Date: Thu, 27 Dec 2018 18:52:28 +0100 Subject: [PATCH 3/3] even better name? --- .../Services/Navigation/FindUsagesService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs index f8f4b3a2e1..61bff37cb6 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/Navigation/FindUsagesService.cs @@ -39,10 +39,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 ignoreCanBeReferencedByName = symbol is IMethodSymbol method && + var dontRequireReferenceByName = symbol is IMethodSymbol method && (method.MethodKind == MethodKind.Constructor || method.MethodKind == MethodKind.UserDefinedOperator); - foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || ignoreCanBeReferencedByName)) + foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || dontRequireReferenceByName)) { foreach (var location in usage.Locations) {