
In our language, the classification of an identifier can change as text changes in another part of the document. The tagging and classification works fine; however, when text changing in the document causes the identifiers in another part to change classification, the view doesn't know that they changed. The OnTagsChanged is supposed to handle this AFAIK. Given our situation, I don't know the ranges of the identifiers that need to be updated. This leaves us with the coloring of the identifiers being off until something invalidates the editor causing a refresh.
To get around this, we override GetTags and trigger the event saying that the whole snapshot is outdated with OnTagsChanged. Is there a better way to do this?
public class IdentifierHighlightingClassificationTagger : TokenTagger
{
static IdentifierHighlightingClassificationTagger()
{
_Register(XxxClassificationTypes.IdentifierHighlight, Brushes.BlueViolet);
// ..
// Other classification types are registered with their appropriate colors
}
public IdentifierHighlightingClassificationTagger(ICodeDocument document)
: base(document)
{
}
private static void _Register(IClassificationType classificationType, Brush brush)
{
AmbientHighlightingStyleRegistry.Instance.Register(classificationType, new HighlightingStyle(brush));
}
public override IEnumerable<TagSnapshotRange<ITokenTag>> GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
{
var tags = base.GetTags(snapshotRanges, parameter);
OnTagsChanged(new TagsChangedEventArgs(Document.CurrentSnapshot.SnapshotRange)); // Force the view to refresh based on the whole document.
return tags;
}
public override IClassificationType ClassifyToken(IToken token)
{
// Custom code that gives classification, this works fine
}
}