/vs-extensibility-skills:adding-editor-adornmentsfrom vs-extensibility-skills
Adds visual adornments (decorations, overlays, highlights) to the Visual Studio text editor using extension APIs. Covers VisualStudio.Extensibility, VSIX Community Toolkit, and VSSDK approaches.
Ships in vs-extensibility-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Adornments are WPF visuals drawn on the text editor surface. They can highlight text, add inline icons, render overlays, or display viewport-relative UI. Common scenarios:
Adornments are one of the most powerful editor integration points — they let you draw arbitrary WPF content directly on the code surface without modifying the underlying text. The critical constraint is performance: LayoutChanged fires on every scroll and edit, so adornment rendering must be fast.
When to use adornments vs. alternatives:
IGlyphFactory (see vs-editor-margin).vsixmanifest[Export(typeof(AdornmentLayerDefinition))])Any extension that uses MEF editor exports must declare the MEF asset type in the .vsixmanifest file. Without this, Visual Studio will not discover your MEF components and your adornment will not load.
Add this inside the <Assets> element of source.extension.vsixmanifest:
<Asset Type="Microsoft.VisualStudio.MefComponent"
d:Source="Project"
d:ProjectName="%CurrentProject%"
Path="|%CurrentProject%|" />
If you are using a multi-project solution, replace %CurrentProject% with the project name that contains the MEF exports. The Visual Studio VSIX project template usually includes this automatically, but if your adornment is not loading, this is the first thing to check.
The VisualStudio.Extensibility SDK does not currently support editor adornments. There is no out-of-process API for rendering custom WPF visuals on the editor surface.
If you need editor adornments, use the VSIX Community Toolkit or VSSDK (in-process) approach.
For some visual scenarios, you may be able to use ITextViewChangedListener combined with diagnostics/text markers in the new model, but full custom WPF adornments require in-process MEF.
The Community Toolkit does not add a separate adornment API — adornments use the same MEF-based VSSDK APIs. The toolkit simplifies package initialization, but the adornment itself uses IWpfTextViewCreationListener and AdornmentLayer from the editor MEF model.
NuGet packages: Community.VisualStudio.Toolkit, Microsoft.VisualStudio.Editor, Microsoft.VisualStudio.Text.UI.Wpf
Key namespaces: Microsoft.VisualStudio.Text.Editor, Microsoft.VisualStudio.Utilities
The code below is identical to the VSSDK approach — the toolkit does not wrap this API.
Editor adornments are created by:
[Export(typeof(AdornmentLayerDefinition))]IWpfTextViewCreationListener to attach your adornment logic when an editor opensNuGet packages: Microsoft.VisualStudio.SDK, Microsoft.VisualStudio.Editor, Microsoft.VisualStudio.Text.UI.Wpf
Key namespaces: Microsoft.VisualStudio.Text.Editor, Microsoft.VisualStudio.Text.Formatting, Microsoft.VisualStudio.Utilities
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
namespace MyExtension;
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
internal sealed class HighlightAdornmentFactory : IWpfTextViewCreationListener
{
[Export(typeof(AdornmentLayerDefinition))]
[Name("MyHighlightAdornment")]
[Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)]
private AdornmentLayerDefinition _editorAdornmentLayer;
public void TextViewCreated(IWpfTextView textView)
{
// Create the adornment manager and attach it to the view
new HighlightAdornment(textView);
}
}
This example highlights every occurrence of "TODO" with a colored background:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Formatting;
namespace MyExtension;
internal sealed class HighlightAdornment
{
private const string AdornmentLayerName = "MyHighlightAdornment";
private readonly IAdornmentLayer _layer;
private readonly IWpfTextView _view;
private readonly Brush _brush;
public HighlightAdornment(IWpfTextView view)
{
_view = view;
_layer = view.GetAdornmentLayer(AdornmentLayerName);
_brush = new SolidColorBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00));
_brush.Freeze();
_view.LayoutChanged += OnLayoutChanged;
}
private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
foreach (ITextViewLine line in e.NewOrReformattedLines)
{
CreateVisuals(line);
}
}
private void CreateVisuals(ITextViewLine line)
{
IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
string text = line.Extent.GetText();
int index = 0;
while ((index = text.IndexOf("TODO", index, StringComparison.OrdinalIgnoreCase)) >= 0)
{
var span = new SnapshotSpan(_view.TextSnapshot, line.Start + index, 4);
Geometry geometry = textViewLines.GetMarkerGeometry(span);
if (geometry != null)
{
var drawing = new GeometryDrawing(_brush, null, geometry);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image
{
Source = drawingImage,
Width = geometry.Bounds.Width,
Height = geometry.Bounds.Height,
};
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
_layer.AddAdornment(
AdornmentPositioningBehavior.TextRelative,
span,
tag: null,
adornment: image,
removedCallback: null);
}
index += 4;
}
}
}
| Behavior | Description |
|---|---|
AdornmentPositioningBehavior.TextRelative | Moves with the text it's attached to (most common) |
AdornmentPositioningBehavior.ViewportRelative | Fixed position in the viewport (e.g., watermarks) |
AdornmentPositioningBehavior.OwnerControlled | You manage the position manually |
Use [Order] to control where your adornment renders relative to built-in layers:
| Layer | Description |
|---|---|
PredefinedAdornmentLayers.Selection | The selection highlight |
PredefinedAdornmentLayers.Text | The actual text glyphs |
PredefinedAdornmentLayers.Caret | The caret |
PredefinedAdornmentLayers.CurrentLineHighlighter | Current line highlight |
PredefinedAdornmentLayers.TextMarker | Text marker decorations |
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text.Editor;
namespace MyExtension;
internal sealed class WatermarkAdornment
{
private const string AdornmentLayerName = "MyWatermarkAdornment";
private readonly IAdornmentLayer _layer;
private readonly IWpfTextView _view;
private readonly UIElement _watermark;
public WatermarkAdornment(IWpfTextView view)
{
_view = view;
_layer = view.GetAdornmentLayer(AdornmentLayerName);
_watermark = new TextBlock
{
Text = "DRAFT",
FontSize = 48,
Foreground = new SolidColorBrush(Color.FromArgb(0x30, 0xFF, 0x00, 0x00)),
IsHitTestVisible = false,
};
_view.ViewportHeightChanged += (s, e) => Render();
_view.ViewportWidthChanged += (s, e) => Render();
Render();
}
private void Render()
{
_layer.RemoveAllAdornments();
Canvas.SetLeft(_watermark, _view.ViewportRight - 200);
Canvas.SetTop(_watermark, _view.ViewportTop + 10);
_layer.AddAdornment(
AdornmentPositioningBehavior.ViewportRelative,
null,
null,
_watermark,
null);
}
}
UIElement instances drawn on an IAdornmentLayer.LayoutChanged for text-relative adornments to redraw on scroll/edit.IsHitTestVisible = false on adornments that should not intercept mouse clicks.[ContentType] attribute controls which file types activate your adornment (e.g., "CSharp", "text", "code").[TextViewRole] attribute limits which editor instances trigger your listener (use PredefinedTextViewRoles.Document to avoid triggering in peek, diff, etc.)..vsixmanifest — see the top of this document.IWpfTextViewCreationListener with MEF exports. Define an AdornmentLayerDefinition, subscribe to LayoutChanged, and draw WPF elements on the layer.source.extension.vsixmanifest or the adornment will silently fail to load.ContentType and TextViewRole to scope your adornment to the right editors..vsixmanifest (the #1 cause). Also verify [ContentType] matches the file type you're testing with and [TextViewRole] isn't filtering out the editor instance.textViewLines.GetCharacterBounds() or GetTextMarkerGeometry() to calculate positions. Character positions change on scroll and view resize — recalculate in LayoutChanged.LayoutChanged handler is doing too much work. Pre-compute data on a background thread and only draw from cache during layout.IsHitTestVisible = false on decorative (non-interactive) adornment elements.ITextView.Closed to remove your handlers.Do NOT forget
IsHitTestVisible = falseon decorative adornment elements — without it, they steal mouse clicks and selections from the editor text underneath.
Do NOT forget to unsubscribe from
ITextView.LayoutChangedwhen the view closes — subscribe toITextView.Closedand remove handlers there. Leaked subscriptions cause memory leaks.
Do NOT forget the
MefComponentasset type in.vsixmanifest— without it, yourIWpfTextViewCreationListeneris silently ignored (#1 cause of "my adornment doesn't show up").
Do NOT do expensive work in
LayoutChanged— it fires on every scroll, resize, and edit. Pre-compute data on a background thread; only read from cache during layout.
Do NOT attempt to use VisualStudio.Extensibility for editor adornments — it doesn't support them. The VSSDK in-process MEF approach is the only option.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (madskristensen/vs-agent-plugins) — no native marketplace selected
npx claudepluginhub p/madskristensen-vs-extensibility-skills41 skills in this plugin
/adding-codelens-indicatorsAdd custom CodeLens indicators that display inline information above code elements in the Visual Studio editor. Use when the user asks how to add a CodeLens indicator, show inline data above methods or classes, create a custom CodeLens provider, implement IAsyncCodeLensDataPointProvider, display git history or test status in CodeLens, or add a details popup to CodeLens entries. Covers VSSDK / VSIX Community Toolkit (in-process + out-of-process CodeLens service). VisualStudio.Extensibility (out-of-process) does not have a dedicated CodeLens API./adding-commandsAdd commands (menu items, toolbar buttons) to Visual Studio extensions. Use when the user asks how to create a command, add a menu item, add a toolbar button, register a command handler, wire up a .vsct file, use KnownMonikers icons on buttons, or place commands in menus/toolbars in a Visual Studio IDE extension. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-context-menusAdd native-looking context menus to custom WPF UI in Visual Studio extensions (tool windows, custom tree views, list views). Use when the user wants to show a right-click context menu from their own UI that looks native to VS. Covers defining VSCT context menus (type="Context"), grouping commands with separators, and programmatically showing them via IVsUIShell.ShowContextMenu. Do NOT use regular WPF ContextMenu — it won't match VS theming or support command routing. Covers VSSDK and VSIX Community Toolkit (in-process). VisualStudio.Extensibility (out-of-process) does not support VSCT-based context menus on custom UI./adding-editor-classifiersAdd custom syntax highlighting and text classification to the Visual Studio editor. Use when the user asks how to colorize text, add syntax highlighting, create a classifier, highlight keywords, change text colors in the editor, create a custom language colorizer, or implement classification types. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-editor-marginsAdd custom margins to the Visual Studio text editor (gutter icons, side panels, bottom bars). Use when the user asks how to add a gutter, editor margin, side panel, bottom bar, line number gutter, custom glyph margin, or editor chrome. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-intellisense-completionAdd custom IntelliSense completion items to the Visual Studio editor. Use when the user asks how to add IntelliSense, provide auto-complete suggestions, create a completion source, add custom completion items, build a completion provider, implement async completion, or extend IntelliSense for a language. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches.Other plugins' skills for the same job