I'm having trouble finding out how to do this and the Visual Studio SDK Reference is not very helpful either.
I'm trying to figure out how to get a NormalizedSnapshotSpanCollection of XML comments. I want to place an icon next to them... I don't want an icon next to each line, but only next to the first line of each group...
///<summary>SomeXML Comment</summary> [ICON]
///<remarks>some remarks</remarks>
public void Foo()
{
///Some false XML comment line that does not get an icon.
}
Here's what I could get, I think it's pretty similar to what you need. I'm going to update this with more details, if you have questions.
I started with this sample from VS 2010 SDK web site. It is already pretty close to what you need, but requires several more steps.
Download the C# version, unpack to a folder, compile. To run it and test you need to go to Project > Properties > Debug
You need to choose "Start External Program" option and set path to your VS 2010 app, for example
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exeIn the command line arguments set:
/rootsuffix ExpNow you should be able to run it, create some sample project in the opened VS, and if you type anywhere a six-digit number like
00AA00it will be shown as a rectangle with the corresponding color. Close the debug VS instance.Now let's edit some code. In
ColorAdornmentTagger.cscomment the define#define HIDING_TEXT. This will show the adornment next to the text, not instead of it.In the same file you need to find where
SnapshotSpan adornmentSpanis initialized and change the line to:This will place adornment after the text span, not before it.
In the
ColorTagger.cs. Change the regex in constructor, so the constructor now looks likeThis will set the regex to recognize the method commentary line.
Other methods in this class we won't use, you can comment them or return some random color.
In the 'ColorAdornment.cs'. This is the adornment WPF control itself. First change the base class from
ButtontoContentControl. Change the constructor of the class toYou can change the image path to the image path you need. I just downloaded SO logo from Wikipedia and put into my temp folder.
Compile and run. You should be able to see the SO logo next to the comments in the debug VS instance.
Some extra remarks.
First, in this way you just get a working prototype to start with, you should rename the classes and clean-up the code for your needs.
Second, when I was debugging it my debug VS was freezing from time to time. I think this might be related to locks in the
IntraTextAdornmentTagger.csIf you also see freezing, try to update the following method in this way:
and the AsyncUpdate in this way: