public override SourceText WithChanges(IEnumerable <TextChange> changes) { // compute changes against newText to avoid capturing strong references to this ChangedText instance. var changed = (ChangedText)_newText.WithChanges(changes); return(new ChangedText(this, changed._newText, changed._changes)); }
public override SourceText WithChanges(IEnumerable<TextChange> changes) { // compute changes against newText to avoid capturing strong references to this ChangedText instance. // _newText will only ever be one of CompositeText, SubText, StringText or LargeText, so calling WithChanges on it // will either produce a ChangeText instance or the original instance in case of a empty change. var changed = _newText.WithChanges(changes) as ChangedText; if (changed != null) { return new ChangedText(this, changed._newText, changed._info.ChangeRanges); } else { // change was empty, so just return this same instance return this; } }
private static void CharByCharIncrementalParse(SourceText oldText, char newChar, out SyntaxTree incrementalTree, out SyntaxTree parsedTree) { var startTree = SyntaxFactory.ParseSyntaxTree(oldText); // first make certain this text round trips Assert.Equal(oldText.ToString(), startTree.GetCompilationUnitRoot().ToFullString()); var newText = oldText.WithChanges(new TextChange(new TextSpan(oldText.Length, 0), newChar.ToString())); incrementalTree = startTree.WithChangedText(newText); parsedTree = SyntaxFactory.ParseSyntaxTree(newText); }
private static void RemoveText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree) { var newText = oldText.WithChanges(new TextChange(new TextSpan(locationOfChange, widthOfChange), "")); var tree = SyntaxFactory.ParseSyntaxTree(oldText); incrementalTree = tree.WithChangedText(newText); parsedTree = SyntaxFactory.ParseSyntaxTree(newText); }
private static void CommentOutText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree) { var newText = oldText.WithChanges( new TextChange[] { new TextChange(new TextSpan(locationOfChange, 0), "/*"), new TextChange(new TextSpan(locationOfChange + widthOfChange, 0), "*/") }); var tree = SyntaxFactory.ParseSyntaxTree(oldText); incrementalTree = tree.WithChangedText(newText); parsedTree = SyntaxFactory.ParseSyntaxTree(newText); }
protected static void AssertResult(string expected, SourceText sourceText, IList<TextChange> result) { var actual = sourceText.WithChanges(result).ToString(); Assert.Equal(expected, actual); }
private static SourceText FromChanges(SourceText text) { var span = new TextSpan(0, 1); var change = new TextChange(span, text.ToString(span)); var changed = text.WithChanges(change); Assert.NotEqual(text, changed); return changed; }