Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create green (or blue) squiggle adornments with a Visual Studio extension

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:

  1. 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.
  2. In the Tagging namespace there is no mention of a different Tag class implementing ITag. I hoped a WarningTag or InfoTag existed.
  3. 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?!

like image 409
HJLebbink Avatar asked Apr 11 '17 08:04

HJLebbink


People also ask

Are there extensions for Visual Studio?

Extensions are add-ons that allow you to customize and enhance your experience in Visual Studio by adding new features or integrating existing tools. An extension can range in all levels of complexity, but its main purpose is to increase your productivity and cater to your workflow.

What do the colors in Visual Studio mean?

Here's your quick reference to the colors and icons in the editor window's right-hand margin: Yellow: The line has been changed but not yet saved. Green: The line has been changed and saved. Orange: The line has been changed, saved, and the change undone. Little square dots in the middle of the margin: Break points.


1 Answers

The PredefinedErrorTypeNames contains the supported values for the ErrorType property of the ErrorTag.

You got close with "Warning", but the value of PredefinedErrorTypeNames.Warning appears to be "compiler warning".

like image 184
C.Evenhuis Avatar answered Oct 02 '22 16:10

C.Evenhuis