I have a Visual Studio extension that show red error squiggles. I also like to provide squiggles with other colors, for example yellow for warnings.
Creating red squiggles can be done by extending the ITagger class, along the lines:
internal sealed class MySquigglesTagger : ITagger<IErrorTag> {
public IEnumerable<ITagSpan<IErrorTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
foreach (IMappingTagSpan<MyTokenTag> myTokenTag in this._aggregator.GetTags(spans))
SnapshotSpan tagSpan = myTokenTag.Span.GetSpans(this._sourceBuffer)[0];
yield return new TagSpan<IErrorTag>(tagSpan, new ErrorTag("Error", "some info about the error"));
}
}
}
What I have tried:
- My intuition (incorrectly) says that returning an ErrorTag with an different errorType may yield a different type of tag, but whatever string you pass it, the squiggles remain red. Eg. new ErrorTag("Warning") gives red squiggles. The MSDN documentation is almost nonexistent. See ErrorTag.
- In the Tagging namespace there is no mention of a different Tag class implementing ITag. I hoped a WarningTag or InfoTag existed.
- Asked a question on MSDN forum here.
Question: how to create green (or blue or yellow) squiggle adornments? Sadly, even arcane or convoluted solutions are appreciated...
I'm targeting VS2015 and VS2017.
Edit: While typing this question someone at the MSDN forum replied that it cannot be done with the current API. Is it really impossible to make yellow squiggles in Visual Studio?!
The PredefinedErrorTypeNames contains the supported values for the
ErrorType
property of theErrorTag
.You got close with "Warning", but the value of
PredefinedErrorTypeNames.Warning
appears to be "compiler warning".Just to document my own question and answer.
Create a file
SquigglesTaggerProvider.cs
with the following content:Create a file named
SquigglesTagger.cs
with the following content:The
PredefinedErrorTypeNames
has different errors predefined.The code is taken from my repository here.