Skip to content

Commit

Permalink
Merge pull request #69708 from Cosifne/dev/shech/inlineRenameFix
Browse files Browse the repository at this point in the history
Fix the ArgumentOutOfRangeException in inline rename
  • Loading branch information
Cosifne authored Aug 31, 2023
2 parents 2972168 + 95772f7 commit 1ef50ab
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public string IdentifierText
{
if (value != _session.ReplacementText)
{
_session.ApplyReplacementText(value, propagateEditImmediately: true);
_session.ApplyReplacementText(value, propagateEditImmediately: true, updateSelection: false);
NotifyPropertyChanged(nameof(IdentifierText));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ private bool AreAllReferenceSpansMappable()
{
// in tests `ActiveTextview` could be null so don't depend on it
return ActiveTextView == null ||
_referenceSpanToLinkedRenameSpanMap.Keys
.Select(s => s.ToSpan())
_referenceSpanToLinkedRenameSpanMap.Values
.Select(renameTrackingSpan => renameTrackingSpan.TrackingSpan.GetSpan(_subjectBuffer.CurrentSnapshot))
.All(s =>
s.End <= _subjectBuffer.CurrentSnapshot.Length && // span is valid for the snapshot
ActiveTextView.GetSpanInView(_subjectBuffer.CurrentSnapshot.GetSpan(s)).Count != 0); // spans were successfully projected
Expand Down
4 changes: 2 additions & 2 deletions src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private void SetReferenceLocations(ImmutableArray<InlineRenameLocation> location
/// <summary>
/// Updates the replacement text for the rename session and propagates it to all live buffers.
/// </summary>
internal void ApplyReplacementText(string replacementText, bool propagateEditImmediately)
internal void ApplyReplacementText(string replacementText, bool propagateEditImmediately, bool updateSelection = true)
{
_threadingContext.ThrowIfNotOnUIThread();
VerifyNotDismissed();
Expand All @@ -460,7 +460,7 @@ internal void ApplyReplacementText(string replacementText, bool propagateEditImm
{
foreach (var openBuffer in _openTextBuffers.Values)
{
openBuffer.ApplyReplacementText();
openBuffer.ApplyReplacementText(updateSelection);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,38 @@ class p$$rogram
static void Main(string[] args)
{
}
}", HangMitigatingCancellationToken);
}

[IdeFact, WorkItem("https://github.com/dotnet/roslyn/issues/68880")]
public async Task VerifyTextSync()
{
await TestServices.SolutionExplorer.AddFileAsync(ProjectName, "Program.cs",
@"
public class Class2
{
public int Field123;
}", cancellationToken: HangMitigatingCancellationToken);

await TestServices.SolutionExplorer.OpenFileAsync(ProjectName, "Program.cs", HangMitigatingCancellationToken);
await TestServices.Editor.PlaceCaretAsync("Field123", charsOffset: 0, HangMitigatingCancellationToken);
await TestServices.InlineRename.InvokeAsync(HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync(new InputKey[] { "F", "i" }, HangMitigatingCancellationToken);
await TestServices.Workspace.WaitForRenameAsync(HangMitigatingCancellationToken);
await TestServices.EditorVerifier.TextEqualsAsync(
@"
public class Class2
{
public int Fi$$;
}", HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync(new InputKey[] { "e", "l", "d", "3", "2", "1" }, HangMitigatingCancellationToken);

await TestServices.Workspace.WaitForRenameAsync(HangMitigatingCancellationToken);
await TestServices.EditorVerifier.TextEqualsAsync(
@"
public class Class2
{
public int Field321$$;
}", HangMitigatingCancellationToken);
}
}
Expand Down

0 comments on commit 1ef50ab

Please sign in to comment.