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
54 changes: 54 additions & 0 deletions src/EditorFeatures/Test2/Rename/InlineRenameTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2473,5 +2473,59 @@ class [|C|]
</Workspace>, host:=host, renameTo:="MyNewProperty")
End Using
End Sub

<WpfTheory>
<CombinatorialData, Trait(Traits.Feature, Traits.Features.Rename)>
Public Sub RenameClassWithAttributeName(host As RenameTestHost)
Using result = RenameEngineResult.Create(_outputHelper,
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
<![CDATA[
public class [|$$MyClassAttribute|] : System.Attribute
{
public [|MyClassAttribute|]()
{

}
}
']]>
</Document>
</Project>
</Workspace>, host:=host, renameTo:="MyClassAttribute2")
End Using
End Sub

<WpfTheory>
<CombinatorialData, Trait(Traits.Feature, Traits.Features.Rename)>
Public Async Function RenameClassWithAttributeName2(host As RenameTestHost) As Task
Using workspace = CreateWorkspaceWithWaiter(
<Workspace>
<Project Language="C#" CommonReferences="true" LanguageVersion="preview">
<Document>
public class [|MyClass$$Attribute|] : System.Attribute
{
public [|MyClassAttribute|]()
{

}
}
</Document>
</Project>
</Workspace>, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ISyntaxFactsService>()?.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;
Expand Down
Loading