diff --git a/src/EditorFeatures/Test2/Rename/InlineRenameTests.vb b/src/EditorFeatures/Test2/Rename/InlineRenameTests.vb index 0d6e86c3b498f..2013f15300b3b 100644 --- a/src/EditorFeatures/Test2/Rename/InlineRenameTests.vb +++ b/src/EditorFeatures/Test2/Rename/InlineRenameTests.vb @@ -2473,5 +2473,59 @@ class [|C|] , host:=host, renameTo:="MyNewProperty") End Using End Sub + + + + Public Sub RenameClassWithAttributeName(host As RenameTestHost) + Using result = RenameEngineResult.Create(_outputHelper, + + + + + + + , host:=host, renameTo:="MyClassAttribute2") + End Using + End Sub + + + + Public Async Function RenameClassWithAttributeName2(host As RenameTestHost) As Task + Using workspace = CreateWorkspaceWithWaiter( + + + + public class [|MyClass$$Attribute|] : System.Attribute + { + public [|MyClassAttribute|]() + { + + } + } + + + , host) + + Dim session = StartSession(workspace) + + ' Type a bit in the file + Dim caretPosition = workspace.Documents.Single(Function(d) d.CursorPosition.HasValue).CursorPosition.Value + Dim textBuffer = workspace.Documents.Single().GetTextBuffer() + + textBuffer.Insert(caretPosition, "2") + + Await session.CommitAsync(previewChanges:=False, editorOperationContext:=Nothing) + + Await VerifyTagsAreCorrect(workspace) + End Using + End Function End Class End Namespace diff --git a/src/VisualStudio/Core/Def/InlineRename/InlineRenameUndoManager.cs b/src/VisualStudio/Core/Def/InlineRename/InlineRenameUndoManager.cs index 3548aa6d7dc5a..ad7fce549b32a 100644 --- a/src/VisualStudio/Core/Def/InlineRename/InlineRenameUndoManager.cs +++ b/src/VisualStudio/Core/Def/InlineRename/InlineRenameUndoManager.cs @@ -15,6 +15,9 @@ using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Editor; using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Text; @@ -171,7 +174,14 @@ public void ApplyCurrentState(ITextBuffer subjectBuffer, object propagateSpansEd return; } - ApplyReplacementText(subjectBuffer, bufferUndoState.TextUndoHistory, propagateSpansEditTag, spans, this.currentState.ReplacementText); + var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); + var isCaseSensitive = document?.GetLanguageService()?.IsCaseSensitive ?? true; + + // This is where we apply the replacement text to each inline preview in the buffer. + // Needs to remove the "Attribute" suffix, since the inline preview does not include the "Attribute" suffix in the replacement span, + // so that the user does not see the suffix twice. + ApplyReplacementText(subjectBuffer, bufferUndoState.TextUndoHistory, propagateSpansEditTag, spans, + currentState.ReplacementText.GetWithoutAttributeSuffix(isCaseSensitive) ?? currentState.ReplacementText); // Here we create the descriptions for the redo list dropdown. var undoManager = bufferUndoState.UndoManager;