private static ClassifiedSpan[] ConvertMultiLineToSingleLineSpans(SourceText text, ClassifiedSpan[] classifiedSpans) { using var _ = ArrayBuilder <ClassifiedSpan> .GetInstance(out var updatedClassifiedSpans); for (var spanIndex = 0; spanIndex < classifiedSpans.Length; spanIndex++) { var span = classifiedSpans[spanIndex]; text.GetLinesAndOffsets(span.TextSpan, out var startLine, out var startOffset, out var endLine, out var endOffSet); // If the start and end of the classified span are not on the same line, we're dealing with a multi-line span. // Since VS doesn't support multi-line spans/tokens, we need to break the span up into single-line spans. if (startLine != endLine) { spanIndex = ConvertToSingleLineSpan( text, classifiedSpans, updatedClassifiedSpans, spanIndex, span.ClassificationType, startLine, startOffset, endLine, endOffSet); } else { // This is already a single-line span, so no modification is necessary. updatedClassifiedSpans.Add(span); } } return(updatedClassifiedSpans.ToArray());
public static VsTextSpan GetVsTextSpanForSpan(this SourceText text, TextSpan textSpan) { text.GetLinesAndOffsets(textSpan, out var startLine, out var startOffset, out var endLine, out var endOffset); return(new VsTextSpan() { iStartLine = startLine, iStartIndex = startOffset, iEndLine = endLine, iEndIndex = endOffset }); }
public static Range AsRange(this TextSpan span, SourceText sourceText) { if (sourceText is null) { throw new ArgumentNullException(nameof(sourceText)); } sourceText.GetLinesAndOffsets(span, out var startLine, out var startChar, out var endLine, out var endChar); var range = new Range { Start = new Position(startLine, startChar), End = new Position(endLine, endChar) }; return(range); }