Here is probably the simplest colorizer code:
namespace Ciper { [Export(typeof(IClassifierProvider)), ContentType("text")] internal class CProvider : IClassifierProvider { [Import] IClassificationTypeRegistryService ctrs = null; [Export, Name("ciper.text"), BaseDefinition("text")] internal static ClassificationTypeDefinition CTD; [Export(typeof(EditorFormatDefinition)), Name("ciper.text.format"), ClassificationType(ClassificationTypeNames = "ciper.text")] internal class CFD : ClassificationFormatDefinition { public CFD() { ForegroundColor = System.Windows.Media.Colors.DarkMagenta; } } public IClassifier GetClassifier(ITextBuffer buffer) { return new C(ctrs.GetClassificationType("ciper.text")); } } class C : IClassifier { IClassificationType ct; public C(IClassificationType ct) { this.ct = ct; } public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) { return new[] { new ClassificationSpan(span, ct) }; } public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged; } }
This will paint everything that is not yet classified in magenta.
Leave a comment