public TagSpan<IOutliningRegionTag> AsOutliningRegionTag()
{
SnapshotSpan span = this.AsSnapshotSpan();
string hoverText = span.GetText();
// removing first empty line
string[] lines = hoverText.Split(new string[] { "\r\n" }, StringSplitOptions.None);
string tabSpaces = new string(' ', Tagger.TabSize);
int empty = 0;
while (empty < lines.Length && string.IsNullOrWhiteSpace(lines[empty]))
empty++;
string[] textLines = new string[Math.Min(lines.Length - empty, 25)];
for (int i = 0; i < textLines.Length; i++)
textLines[i] = lines[i + empty].Replace("\t", tabSpaces);
//removing redundant indentation
//calculating minimal indentation
int minIndent = int.MaxValue;
foreach (string s in textLines)
minIndent = Math.Min(minIndent, GetIndentation(s));
// allocating a bit larger buffer
StringBuilder builder = new StringBuilder(hoverText.Length);
for (int i = 0; i < textLines.Length - 1; i++)
{
// unindenting every line
builder.AppendLine(textLines[i].Length > minIndent ? textLines[i].Substring(minIndent) : "");
}
// using Append() instead of AppendLine() to prevent extra newline
if (textLines.Length == lines.Length - empty)
builder.Append(textLines[textLines.Length - 1].Length > minIndent ? textLines[textLines.Length - 1].Substring(minIndent) : "");
else
builder.Append("...");
return new TagSpan<IOutliningRegionTag>(span, new OutliningRegionTag(false, false, GetCollapsedText(), builder.ToString()));
//return new TagSpan<IOutliningRegionTag>(span, new OutliningRegionTag(false, false, GetCollapsedText(), hoverText));
}