Override the font/color of code patterns

I'd like to be able to override the display properties of source code if it matches a certain pattern. For example I'd like all constants that start with the text "Archive" to appear in bold pink whereever used:

private const string ArchiveTypeIdEntry = "typeId";
writer.WriteGuid128(ArchiveTypeIdEntry, typeId);

Is this possible with ReSharper (or with some other Visual Studio add-on if need be)?
I'm using Visual Studio Professional 2013 with ReSharper 8.2.1

1 comment
Comment actions Permalink

I don't know of any off-the-shelf add on that can do this for you. You'll need to write your own Visual Studio extension, or ReSharper extension to do this. This might actually be easier to do in Visual Studio, since VS requires all editor extension highlights to be statically registered via MEF in VS extensions. ReSharper has a bunch of highlights registered (all the "ReSharper" items you can see in Fonts and Colours), but loads ReSharper extensions dynamically, so they don't get a chance to register any MEF editor classifications.

However, it might be possible to dynamically call Visual Studio's IClassificationTypeRegistryService.Create(Transient)ClassificationType to create a classification type in VS, and then use ReSharper's highlight mechanism to create a TEXT highlight with an ID the same as the new classification type. I haven't tried this, though...


Please sign in to leave a comment.