Here you also store the maximum length registered extensions
Extending the New Editor ❘273
}
else
{
var classificationType = _fileAssociations[keyFound].StartsWith(“text”) ? _textClassification
: _nonTextClassification;
int wordLength = keyFound.Length;
classifications.Add(new ClassificationSpan(
new SnapshotSpan(span.Snapshot,
new Span(wordStart + span.Start, wordLength)), classificationType)); searchOffset = wordStart + wordLength;
}
}
while (true);
return classifications;
}
}
}
There are many ways to do that. The algorithm used here seems a bit complicated; you may create a simpler solution. However, there are two important things to be keep in mind when programming the GetClassificationSpan method:
➤ The text spans returned must be ordered by their starting position and non - overlapping, in order to be displayed correctly in the editor.
274❘CHAPTER 6VISUAL STUDIO EXTENSIBILITY
Run the extension with Debug ➪ Start Without Debugging, and create a new text fi le. Type some text containing fi le extensions, using both text and non - text types. Figure 6 - 38 shows how the classifi er works.
FIGURE 6 - 39: Text Content format is customizable