Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom syntax highlighting for VS 2008

Tags:

I've been using John Lam's Vibrant Ink VS color scheme lately and wanted to tweak it so it highlights the method names for a class with a different color. Turns out there is no option in VS for that.

Resharper has a feature that provides custom syntax highlighting. I was wondering how hard is it to write a little plugin that gives you granular custom syntax highlighting? Are there any open source ad-ins like that out there?

EDIT

Thanks all, I managed to hack stuff up using DXCore and my VS is looking oh so similar to textmate.

VS is looking fantastic http://img14.imageshack.us/img14/637/awesomevsgq1.png

** NOTE **

I had to slightly modify the snippet by Rory so it works with dotted method names and equality operators in C#.

I am now using:

            string name = ea.LanguageElement.Name.Split('.').Last();

            if (name == ("op_Equality")) {
                name = "==";
            } else if (name == "op_Inequality") {
                name = "!=";
            }

            ea.PaintArgs.OverlayText(name, 
                ea.LanguageElement.NameRange.Start, 
                Color.FromArgb(255,204,0)); 
like image 971
Sam Saffron Avatar asked Feb 02 '09 22:02

Sam Saffron


People also ask

How do I change the highlighting syntax?

To configure syntax highlighting, click on “Language” in the top bar, then click the letter the language starts with, and then the language. If you want to define your own language, click on “Language” again, then click on “User Defined Language”, third from the bottom, and then click “Define your language”.


2 Answers

Well as Brian has already said... My PaintIt plugin will give you some idea as to what can be done with the DXCore.

Also there are some other "Decorative plugins" on our "Community Plugin Site" and we have a decent community over in the

DevExpress IDE Tools forums if you have any specific questions.

DXCore is the framework on which RefactorPro and CodeRush are built which should give you an idea of what sort

of graphical capability they are capable of.

That said you do not need either of these tools to use the DXCore.

Everything on the Community Site is "Open Source" (So is PaintIt)

To give you an idea of how simple things are... the following code is all you need to add to a basic plugin template get the basics up and running using DXCore...

Private Sub PlugIn_EditorPaintLanguageElement(ByVal ea As DevExpress.CodeRush.Core.EditorPaintLanguageElementEventArgs) Handles Me.EditorPaintLanguageElement
    If ea.LanguageElement.ElementType = LanguageElementType.Method Then
        ea.PaintArgs.OverlayText(ea.LanguageElement.Name, _
                                 ea.LanguageElement.NameRange.Start, _
                                 Color.HotPink)
    End If
End Sub

I have created a plugin (called CR_ColorizeMemberNames) based on this code and added it to the Community Plugin Site.

The binary is available from my site here.

You need only download and install DXCore and place the binary of the plugin in the plugins folder (Defaults to C:\Program Files\Developer Express Inc\DXCore for Visual Studio .NET\2.0\Bin\Plugins).. Then start VS and your method names should all be in HotPink (Lovely)

like image 181
Rory Becker Avatar answered Sep 18 '22 06:09

Rory Becker


To go beyond the simple keyword coloring, details on the Visual Studio Syntax coloring is defined here; and details to implement here.

These documents outline how the underlying plumbing is, well, plumbed -- and more importantly, goes into detail on how to wire in your own --

like image 22
Borzio Avatar answered Sep 21 '22 06:09

Borzio