Last week, I decided to create a Visual Studio Extension for measuring C++ code coverage. Basically I needed it myself for my daily work. What I came up with was the project that can be found https://github.com/atlaste/CPPCoverage .
Most it works fine. However, I have some issues with adornment layers:
One of the features of the project is to create highlighting of the (un)covered code. Highlighting itself works fine, but it seems to interfere with the selection code of Visual Studio:
The relevant code that's responsible for the highlighting:
private void HighlightCoverage(CoverageState coverdata, ITextViewLine line)
IWpfTextViewLineCollection textViewLines = view.TextViewLines;
int lineno = 1 + view.TextSnapshot.GetLineNumberFromPosition(line.Extent.Start);
CoverageState covered = lineno < coverdata.Length ?
coverdata[lineno] : CoverageState.Irrelevant;
if (covered != CoverageState.Irrelevant)
SnapshotSpan span = new SnapshotSpan(view.TextSnapshot,
Geometry g = textViewLines.GetMarkerGeometry(span);
if (g != null)
GeometryDrawing drawing = (covered == CoverageState.Covered) ?
new GeometryDrawing(coveredBrush, coveredPen, g) :
new GeometryDrawing(uncoveredBrush, uncoveredPen, g);
DrawingImage drawingImage = new DrawingImage(drawing);
Image image = new Image();
image.Source = drawingImage;
//Align the image with the top of the bounds of the text geometry
span, null, image, null);
Asked 7 years ago and still there is next to ZERO info about adornments and extending Visual Studio on the net.
Here is how you do it:
When you create a TextAdornment class instance using VS wizard (for instance: right click on project => Add Item) you receive two files: the first one is the class with the name you picked, and the other one is
Find that file in solution explorer and open it.
/// <summary> /// Defines the adornment layer for the adornment. This layer is ordered /// after the selection layer in the Z-order /// </summary> [Export(typeof(AdornmentLayerDefinition))] [Name("TextAdornment")] [Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)] private AdornmentLayerDefinition editorAdornmentLayer;
[Order(Before = PredefinedAdornmentLayers.BraceCompletion)]