From fdedcf539aa84b8be651d5e186b1c95690038a7e Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Sun, 17 Jul 2022 18:00:05 -0700 Subject: [PATCH] Fix new rename showing overloads when not applicable (#62559) --- .../UI/Adornment/RenameFlyout.xaml | 2 +- .../UI/Adornment/RenameFlyoutViewModel.cs | 16 ++++- .../UI/InlineRenameAdornmentManager.cs | 2 +- ...hboardTests.vb => RenameViewModelTests.vb} | 58 ++++++++++++------- 4 files changed, 54 insertions(+), 24 deletions(-) rename src/EditorFeatures/Test2/Rename/{DashboardTests.vb => RenameViewModelTests.vb} (94%) diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/Adornment/RenameFlyout.xaml b/src/EditorFeatures/Core.Wpf/InlineRename/UI/Adornment/RenameFlyout.xaml index a991bac80d70..277ee8c331ec 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/UI/Adornment/RenameFlyout.xaml +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/Adornment/RenameFlyout.xaml @@ -99,7 +99,7 @@ + Name="OverloadsCheckbox" Visibility="{Binding IsRenameOverloadsVisible, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" IsEnabled="{Binding IsRenameOverloadsEditable}" /> _session; + public bool AllowFileRename => _session.FileRenameInfo == InlineRenameFileRenameInfo.Allowed && _isReplacementTextValid; public bool ShowFileRename => _session.FileRenameInfo != InlineRenameFileRenameInfo.NotAllowed; @@ -131,6 +135,9 @@ public bool IsExpanded public bool IsRenameOverloadsEditable => !_session.MustRenameOverloads; + public bool IsRenameOverloadsVisible + => _session.HasRenameOverloads; + public TextSpan StartingSelection { get; } public void Submit() @@ -157,6 +164,13 @@ public void Dispose() /// public void RegisterOleComponent() { + // In unit testing we won't have an OleComponentManager available, so + // calls to OleComponent.CreateHostedComponent will throw + if (!_registerOleComponent) + { + return; + } + Debug.Assert(_oleComponent is null); _oleComponent = OleComponent.CreateHostedComponent("Microsoft CodeAnalysis Inline Rename"); diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/InlineRenameAdornmentManager.cs b/src/EditorFeatures/Core.Wpf/InlineRename/UI/InlineRenameAdornmentManager.cs index 428a4f83f8e5..d8904c712b56 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/UI/InlineRenameAdornmentManager.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/InlineRenameAdornmentManager.cs @@ -93,7 +93,7 @@ private void UpdateAdornments() var identifierSelection = new TextSpan(start, length); var adornment = new RenameFlyout( - (RenameFlyoutViewModel)s_createdViewModels.GetValue(_renameService.ActiveSession, session => new RenameFlyoutViewModel(session, identifierSelection)), + (RenameFlyoutViewModel)s_createdViewModels.GetValue(_renameService.ActiveSession, session => new RenameFlyoutViewModel(session, identifierSelection, registerOleComponent: true)), _textView); _adornmentLayer.AddAdornment( diff --git a/src/EditorFeatures/Test2/Rename/DashboardTests.vb b/src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb similarity index 94% rename from src/EditorFeatures/Test2/Rename/DashboardTests.vb rename to src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb index 6a1906fa2159..3acca4ab4fff 100644 --- a/src/EditorFeatures/Test2/Rename/DashboardTests.vb +++ b/src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb @@ -11,11 +11,11 @@ Imports Microsoft.CodeAnalysis.Rename Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename <[UseExportProvider]> - Public Class DashboardTests + Public Class RenameViewModelTests Public Async Function RenameWithNoOverload(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -41,7 +41,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename Public Async Function RenameWithOverload(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -73,7 +73,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename Public Async Function RenameWithInvalidOverload(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( @@ -103,7 +103,7 @@ class Program Public Async Function RenameAttributeAlias(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -123,7 +123,7 @@ class AttributeAttribute : System.Attribute { } Public Async Function RenameWithOverloadAndInStringsAndComments(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -160,7 +160,7 @@ class AttributeAttribute : System.Attribute { } Public Async Function RenameInComments(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -198,7 +198,7 @@ class $$Program Public Async Function RenameInStrings(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -236,7 +236,7 @@ class $$Program Public Async Function RenameInCommentsAndStrings(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -274,7 +274,7 @@ class $$Program Public Async Function NonConflictingEditWithMultipleLocations(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -295,7 +295,7 @@ class $$Program Public Async Function NonConflictingEditWithSingleLocation(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -316,7 +316,7 @@ class $$Program Public Async Function ParameterConflictingWithInstanceField(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -341,7 +341,7 @@ class $$Program Public Async Function ParameterConflictingWithInstanceFieldMoreThanOnce(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -365,7 +365,7 @@ class $$Program Public Async Function ParameterConflictingWithLocal_Unresolvable(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -388,7 +388,7 @@ class $$Program Public Async Function MoreThanOneUnresolvableConflicts(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -413,7 +413,7 @@ class $$Program Public Async Function ConflictsAcrossLanguages_Resolvable(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -450,7 +450,7 @@ class $$Program Public Async Function RenameWithNameof_FromDefinition_DoesNotForceRenameOverloadsOption(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -474,7 +474,7 @@ class C Public Async Function RenameWithNameof_FromReference_DoesForceRenameOverloadsOption(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -498,7 +498,7 @@ class C Public Async Function RenameWithNameof_FromDefinition_WithRenameOverloads_Cascading(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( ( @@ -530,7 +530,7 @@ class D : B hasRenameOverload:=True) End Function - Friend Shared Async Function VerifyDashboard( + Friend Shared Async Function VerifyViewModels( test As XElement, newName As String, searchResultText As String, @@ -613,6 +613,22 @@ class D : B Assert.Equal(severity, model.Severity) End Using + Using flyout = New RenameFlyout( + New RenameFlyoutViewModel(DirectCast(sessionInfo.Session, InlineRenameSession), selectionSpan:=Nothing, registerOleComponent:=False), ' Don't registerOleComponent in tests, it requires OleComponentManagers that don't exist in our host + textView:=cursorDocument.GetTextView()) + + Await WaitForRename(workspace) + + Dim model = DirectCast(flyout.DataContext, RenameFlyoutViewModel) + + Assert.Equal(hasRenameOverload, model.Session.HasRenameOverloads) + Assert.Equal(hasRenameOverload, model.IsRenameOverloadsVisible) + Assert.Equal(isRenameOverloadsEditable, model.IsRenameOverloadsEditable) + If Not isRenameOverloadsEditable Then + Assert.True(model.RenameOverloadsFlag) + End If + End Using + sessionInfo.Session.Cancel() End Using End Function @@ -620,7 +636,7 @@ class D : B Public Async Function RenameWithReferenceInUnchangeableDocument(host As RenameTestHost) As Task - Await VerifyDashboard( + Await VerifyViewModels( (