[Export( typeof (IClassifierProvider))]
[ContentType( "text" )]
internal class Z80EditorClassifierProvider : IClassifierProvider
{
[Import]
internal IClassificationTypeRegistryService ClassificationRegistry = null ; // Set via MEF
public IClassifier GetClassifier(ITextBuffer buffer)
{
return buffer.Properties.GetOrCreateSingletonProperty<Z80EditorClassifier>(
delegate { return new Z80EditorClassifier(ClassificationRegistry); });
}
}
* This source code was highlighted with Source Code Highlighter .
class Z80EditorClassifier : IClassifier
{
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
List <ClassificationSpan> result = new List <ClassificationSpan>();
...
return result;
}
}
* This source code was highlighted with Source Code Highlighter .
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
List <ClassificationSpan> result = new List <ClassificationSpan>();
if (span.Length == 0) return result;
ITextSnapshot snapshot = span.Snapshot;
ITextSnapshotLine line = snapshot.GetLineFromPosition(span.Start.Position);
ITextSnapshotLine endLine = snapshot.GetLineFromPosition(span.End.Position);
while ( true )
{
// Process current line
ProcessLine(line, result);
if (line.LineNumber == endLine.LineNumber)
break ;
// Next line
line = snapshot.GetLineFromPosition(line.EndIncludingLineBreak + 1);
}
return result;
}
* This source code was highlighted with Source Code Highlighter .
IClassificationType commentClassifType = registry.GetClassificationType( "z80comment" );
result.Add( new ClassificationSpan(
new SnapshotSpan(line.Snapshot, new Span(line.Start + commentPos, commentLength)),
commentClassifType));
* This source code was highlighted with Source Code Highlighter .
internal static class Z80EditorClassifierClassificationDefinition
{
/// <summary>
/// Defines the "z80operator" classification type - Z80 Assembly Operator.
/// </summary>
[Export( typeof (ClassificationTypeDefinition))]
[Name( "z80operator" )]
internal static ClassificationTypeDefinition Z80OperatorDefinition = null ;
/// <summary>
/// Defines the "z80comment" classification type - Z80 Assembly Comment.
/// </summary>
[Export( typeof (ClassificationTypeDefinition))]
[Name( "z80comment" )]
internal static ClassificationTypeDefinition Z80CommentDefinition = null ;
}
* This source code was highlighted with Source Code Highlighter .
[Export( typeof (EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "z80operator" )]
[Name( "z80operator" )]
[UserVisible( true )]
[Order(Before = Priority.Default)]
internal sealed class Z80EditorOperatorFormat : ClassificationFormatDefinition
{
public Z80EditorOperatorFormat()
{
this .DisplayName = "Z80 Assembly Operator" ;
this .BackgroundColor = Color.FromRgb(230,255,230);
this .ForegroundColor = Colors.Blue;
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/85038/