Skip to content

Commit

Permalink
Raise WorkspaceChanged with a new SourceText even if we have a new sn…
Browse files Browse the repository at this point in the history
…apshot without changes (#25576)

* Fixed DDRIT failure (#25551)

* made sure we raise workspace changed events even when there is no text change.

this is needed to bring workspace up to date with latest text snapshot after we don't merge 2 text snapshot to 1 source text if content is same.

see this for more detail - #24849

* added comments on why we need to process all text change events

* removed changes empty check. now it is possible to have empty changes.

* remove non-empty from comment since set now can be empty.
  • Loading branch information
jasonmalinowski authored and heejaechang committed Mar 20, 2018
1 parent 72c2efe commit 1419a34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Compilers/Core/Portable/Text/TextChangeEventArgs.cs
Expand Up @@ -18,10 +18,10 @@ public class TextChangeEventArgs : EventArgs
/// </summary>
/// <param name="oldText">The text before the change.</param>
/// <param name="newText">The text after the change.</param>
/// <param name="changes">A non-empty set of ranges for the change.</param>
/// <param name="changes">A set of ranges for the change.</param>
public TextChangeEventArgs(SourceText oldText, SourceText newText, IEnumerable<TextChangeRange> changes)
{
if (changes == null || changes.IsEmpty())
if (changes == null)
{
throw new ArgumentException("changes");
}
Expand All @@ -36,7 +36,7 @@ public TextChangeEventArgs(SourceText oldText, SourceText newText, IEnumerable<T
/// </summary>
/// <param name="oldText">The text before the change.</param>
/// <param name="newText">The text after the change.</param>
/// <param name="changes">A non-empty set of ranges for the change.</param>
/// <param name="changes">A set of ranges for the change.</param>
public TextChangeEventArgs(SourceText oldText, SourceText newText, params TextChangeRange[] changes)
: this(oldText, newText, (IEnumerable<TextChangeRange>)changes)
{
Expand Down
26 changes: 16 additions & 10 deletions src/EditorFeatures/Text/Extensions.TextBufferContainer.cs
Expand Up @@ -100,18 +100,24 @@ public override SourceText CurrentText
private void OnTextContentChanged(object sender, TextContentChangedEventArgs args)
{
var changed = this.EtextChanged;
if (changed != null && args.Changes.Count != 0)
if (changed == null)
{
// this should convert given editor snapshots to roslyn forked snapshots
var oldText = (SnapshotSourceText)args.Before.AsText();
var newText = SnapshotSourceText.From(args.After);
_currentText = newText;

var changes = ImmutableArray.CreateRange(args.Changes.Select(c => new TextChangeRange(new TextSpan(c.OldSpan.Start, c.OldSpan.Length), c.NewLength)));
var eventArgs = new TextChangeEventArgs(oldText, newText, changes);
this.LastEventArgs = eventArgs;
changed(sender, eventArgs);
return;
}

// we should process all changes even though there is no text changes
// otherwise, Workspace.CurrentSolution won't move forward to latest ITextSnapshot

// this should convert given editor snapshots to roslyn forked snapshots
var oldText = (SnapshotSourceText)args.Before.AsText();
var newText = SnapshotSourceText.From(args.After);
_currentText = newText;

var changes = ImmutableArray.CreateRange(args.Changes.Select(c => new TextChangeRange(new TextSpan(c.OldSpan.Start, c.OldSpan.Length), c.NewLength)));
var eventArgs = new TextChangeEventArgs(oldText, newText, changes);

this.LastEventArgs = eventArgs;
changed(sender, eventArgs);
}

// These are the event args that were last sent from this text container when the text
Expand Down

0 comments on commit 1419a34

Please sign in to comment.