Skip to content

Instantly share code, notes, and snippets.

@noahrichards
Created July 15, 2009 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahrichards/147450 to your computer and use it in GitHub Desktop.
Save noahrichards/147450 to your computer and use it in GitHub Desktop.
[Export(typeof(ITaggerProvider))]
[TagType(typeof(SquiggleTag))] // this will probably be "IErrorTag" in the next release
[ContentType("text")] // "text" is the base of basically all content types
internal sealed class ToDoTaggerProvider : ITaggerProvider
{
// Note: the "context" arg has been removed, but is still there in Beta 1
public ITagger<T> GetTagger<T>(ITextBuffer buffer, IEnvironment context) where T : ITag
{
return new ToDoTagger() as ITagger<T>;
}
}
internal sealed class ToDoTagger : ITagger<SquiggleTag>
{
// Our simple tagger can ignore this for now
public Event<SnapshotSpanChangedArgs> TagsChanged;
public IEnumerable<ITagSpan<SquiggleTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
foreach(SnapshotSpan span in spans)
{
string spanText = span.GetText();
int index = -1;
while (-1 != (index = spanText.IndexOf("TODO", index + 1, StringComparison.Ordinal)))
{
SnapshotSpan todo = new SnapshotSpan(span.Start + index, 4);
yield return new TagSpan<SquiggleTag>(todo,
new SquiggleTag(StandardErrorTypeService.Other, todo.Start.GetContainingLine().GetText()));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment