protected static (int startIndex, int endIndex) GetIndexes(SeparatedSyntaxList <TNode> list, TextSpan span) { SeparatedSyntaxList <TNode> .Enumerator en = list.GetEnumerator(); if (en.MoveNext()) { int i = 0; while (span.Start >= en.Current.FullSpan.End && en.MoveNext()) { i++; } if (span.Start >= en.Current.FullSpan.Start && span.Start <= en.Current.Span.Start) { int j = i; while (span.End > GetEndIndex(list, en.Current, j) && en.MoveNext()) { j++; } if (span.End >= en.Current.Span.End && span.End <= GetEndIndex(list, en.Current, j)) { return(i, j); } } } return(-1, -1); }
public static SelectionResult Create <TNode>(SeparatedSyntaxList <TNode> list, TextSpan span) where TNode : SyntaxNode { SeparatedSyntaxList <TNode> .Enumerator en = list.GetEnumerator(); if (en.MoveNext()) { int i = 0; while (span.Start >= en.Current.FullSpan.End && en.MoveNext()) { i++; } if (span.Start >= en.Current.FullSpan.Start && span.Start <= en.Current.SpanStart) { int j = i; while (span.End > GetLastIndex(en.Current, j) && en.MoveNext()) { j++; } if (span.End >= en.Current.Span.End && span.End <= GetLastIndex(en.Current, j)) { return(new SelectionResult(i, j)); } } } return(Fail); int GetLastIndex(TNode node, int i) { if (i < list.Count - 1 || list.Count == list.SeparatorCount) { return(list.GetSeparator(i).FullSpan.End); } return(node.FullSpan.End); } }