Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom keyword coloring in Visual Studio 2010+

I'm trying to add custom coloring for only certain keywords in my Visual Studio editor for C# code. I want to be able to color any type that implements IDisposable as a different color. Ideally I'd like to create a simple list of classes/interfaces that derive from IDisposable in some sort of configuration that I can edit. (Although if you said there was a method/plugin that would automatically find all disposable types and color them independently that would be the Holy Grail).

I've done a ton of research and it looks like an "editor classifier" extension might do the trick. However I created one that merely tries to color the word "Stream" and although it does hit my code that attempts to highlight that word, it does not end up highlighted in the editor.

I have added my VS extension to Github here

This really seems like this should be fairly straightforward but I have gone down many alleys on this one only to find dead-ends. Is there a simpler way to do this, or is my extension broken?

Update

Very strange. I just ran my extension again and although it does not highlight the text in the editor it highlights all instances of "Stream" in the popup text when you hover over a type/variable! Is there any way to get it to apply to the editor?

enter image description here

like image 348
Mike Marshall Avatar asked Jul 10 '14 20:07

Mike Marshall


People also ask

How do I enable syntax highlighting in Visual Studio?

On Windows and Linux: press CTRL + K then press M.

How do I change the color of text in Visual Studio?

On the menu bar, choose Tools > Options. In the options list, choose Environment > Fonts and Colors. In the Show settings for list, choose Environment. If you want to change the font for tool windows only, in the Show settings for list, choose All Text Tool Windows.


1 Answers

Depending on wether you are using Jetbrains Resharper or not you may write a plugin for that. That way you are able not only to add visual notification of IDisposable on a variable but also provide quickfixes if, and only if, it is not beeing called, which is what i am assuming you want to catch. Mind you that i can imagine that there's already a R# plugin for that. I know i've considered this too, but i was too lazy to write a plugin for that.

Don't get me wrong btw - If you're not using r# yet you should consider trying it out.

Among others you'd be working with this: API-QuickFix

There are also ways to define custom keywords, as resharper does, given by a custom markup and apply quickfixes to that.

PS: No i don't work at jetbrains. it's just that good :)

UPDATE:

potential VS Extension fix?

check this one out: MSDN Link Highlighting Text

I tried opening your github project but couldn't so i thought i'll just check msdn instead. it seems you are deriving from the wrong class to fulfill your needs?

MSDN keyword "Editors - Extending the Editor - Walkthrough: Highlighting Text"

I know SO wants code on the site, but msdn links going down is rather unlikely and with the given information the content can be found easily enough :)

like image 197
Dbl Avatar answered Sep 27 '22 18:09

Dbl