So I have now gone back and attempted to implement your suggestion, and I think I have done it correctly, however the GetTags code is still never executed, I must still be missing something.
I have created a CustomTagger class here: (note the customTag is just an empty class as in the sample)
public class CustomTagger : TaggerBase<CustomTag>
{
private ICodeDocument document;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// OBJECT
/////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Initializes a new instance of the <c>CustomTagger</c> class.
/// </summary>
/// <param name="document">The document to which this manager is attached.</param>
public CustomTagger(ICodeDocument document) :
base("CustomTagger", null, document, true)
{
this.document = document;
this.Pattern = Error;
}
private string _Error;
public string Error
{
get
{
return _Error;
}
set
{
if (_Error != value)
{
_Error = value;
this.OnTagsChanged(new TagsChangedEventArgs(new TextSnapshotRange(document.CurrentSnapshot, document.CurrentSnapshot.TextRange)));
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC PROCEDURES
/////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Returns the tag ranges that intersect with the specified normalized snapshot ranges.
/// </summary>
/// <param name="snapshotRanges">The collection of normalized snapshot ranges.</param>
/// <param name="parameter">An optional parameter that provides contextual information about the tag request.</param>
/// <returns>The tag ranges that intersect with the specified normalized snapshot ranges.</returns>
public override IEnumerable<TagSnapshotRange<CustomTag>> GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
{
if (snapshotRanges != null)
{
// Loop through the snapshot ranges
foreach (TextSnapshotRange snapshotRange in snapshotRanges)
{
// Get the text of the snapshot range
string text = snapshotRange.Text;
// Look for a regex pattern match
MatchCollection matches = Regex.Matches(text, pattern, RegexOptions.IgnoreCase);
if (matches.Count > 0)
{
// Loop through the matches
foreach (Match match in matches)
{
// Create a tag
CustomTag tag = new CustomTag();
// Yield the tag
yield return new TagSnapshotRange<CustomTag>(
TextSnapshotRange.FromSpan(snapshotRange.Snapshot, snapshotRange.StartOffset + match.Index, match.Length), tag);
}
}
}
}
}
}
then i have registered a CodeDocumentTaggerProvider with the language:
// Register a tagger provider on the language as a service that can create CustomTag objects
language.RegisterService(new CodeDocumentTaggerProvider<CustomTagger>(typeof(CustomTagger)));
Then I have created one instance of a CustomTagger in the constructor of my ViewModel:
this.tag = new CustomTagger(_syntaxEditor.Document);
Then I have a command in my ViewModel that fires when a "Secondary Error" is selected in a listBox outside of the syntaxEditor:
tag.Error = SelectedError;
When i walk through the code, the Error is changed correctly and the OnTagsChanged event is raised, however nothing happens. If i put a breakpoint on the GetTags function, it is never executed. I seem to be missing something. Im hoping you can spot it.
Thanks again for all your help.