internal static TextEdit MergeEdits(TextEdit[] edits, SourceText sourceText) { if (edits.Length == 1) { return(edits[0]); } var textChanges = new List <TextChange>(); foreach (var edit in edits) { var change = new TextChange(edit.Range.AsTextSpan(sourceText), edit.NewText); textChanges.Add(change); } var changedText = sourceText.WithChanges(textChanges); var affectedRange = changedText.GetEncompassingTextChangeRange(sourceText); var spanBeforeChange = affectedRange.Span; var spanAfterChange = new TextSpan(spanBeforeChange.Start, affectedRange.NewLength); var newText = changedText.GetSubTextString(spanAfterChange); var encompassingChange = new TextChange(spanBeforeChange, newText); return(encompassingChange.AsTextEdit(sourceText)); }