Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -9,6 +9,9 @@
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Extensions;

#if !COCOA
using System.Linq;
Expand Down Expand Up @@ -85,6 +88,38 @@ protected override void SetDashboardFocusToPreviousElement(ITextView textView)
return null;
}
}

protected override void Commit(InlineRenameSession activeSession, ITextView textView)
{
try
{
base.Commit(activeSession, textView);
}
catch (NotSupportedException ex)
{
// Session.Commit can throw if it can't commit
// rename operation.
// handle that case gracefully
var notificationService = activeSession.Workspace.Services.GetService<INotificationService>();
notificationService?.SendNotification(ex.Message, title: EditorFeaturesResources.Rename, severity: NotificationSeverity.Error);
}
catch (Exception ex) when (FatalError.ReportAndCatch(ex))
{
// Show a nice error to the user via an info bar
var errorReportingService = activeSession.Workspace.Services.GetService<IErrorReportingService>();
if (errorReportingService is null)
{
return;
}

errorReportingService.ShowGlobalErrorInfo(
string.Format(EditorFeaturesWpfResources.Error_performing_rename_0, ex.Message),
new InfoBarUI(
WorkspacesResources.Show_Stack_Trace,
InfoBarUI.UIKind.HyperLink,
() => errorReportingService.ShowDetailedErrorInfo(ex), closeAfterAction: true));
}
}
#else
protected override bool DashboardShouldReceiveKeyboardNavigation(ITextView textView)
=> false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;

namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
Expand All @@ -20,12 +22,17 @@ public bool ExecuteCommand(ReturnKeyCommandArgs args, CommandExecutionContext co
// InlineRenameSession will call IUIThreadOperationExecutor to sets up our own IUIThreadOperationContext
context.OperationContext.TakeOwnership();

_renameService.ActiveSession.Commit();
SetFocusToTextView(args.TextView);
Commit(_renameService.ActiveSession, args.TextView);
return true;
}

return false;
}

protected virtual void Commit(InlineRenameSession activeSession, ITextView textView)
{
activeSession.Commit();
SetFocusToTextView(textView);
}
}
}