Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto highlight return lines

Eclipse (at least when using Java) has the feature to auto highlight all lines in a method where method returns when I place cursor on return type in method definition.
Is there also such a feature for C# in Visual Studio + ReSharper 5.1.3?

Code example

string Do()
{
  if(/**/)
    return ""; // here

  if(/**/)
    return "1"; // here

  if(/**/)
    return "2"; // here

  throw new Exception(""); // here
 }

When I place cursor on word string in first line of this example the lines marked with // here should be highlighted.

like image 810
brgerner Avatar asked May 16 '12 14:05

brgerner


1 Answers

It looks like the VS2010 extension called Linguist will do close to what you'd like. It can do customized highlighting for any regular expression. It doesn't appear to be able to change it based on your cursor location though.

More information for the extension can be viewed at the github page.

There is no GUI for the settings. Instead there are settings files %LOCALAPPDATA%\Linguist in that you configure.

Since I already have my syntax highlighting the way I'd like it to be with Resharper, I removed all the formatting from the Styles.field file in the standard subdirectory. If you do this you need to leave in all the names though, so it will look similar to:

Styles.field

# If new elements are added (or old ones removed) then Definitons.cs
# and Languages.Init have to be updated.
Name: attribute

Name: command

Name: comment

<<< keep all the names in this file, just remove formatting >>>

You will need to set up one of the named styles to use for highlighting. I did:

Name: emphasis
BackColor: Red

And then I made a file called custom.lang (but you can name yours anything with the .lang extension) in the custom subdirectory. and this is what I did for highlighting return statements:

custom.lang

Language: csharp
Globs: *.cs

Emphasis: \breturn\b
Emphasis: \bthrow\b

That got things working for me. A bit complex, but it's free. Another way to do it might be to clear out the standard\C#.lang file so you can leave other file formattings in place.

And finally another option, since it's on github, you could add a new style definition for highlighted text so we aren't butchering the rest of the formatting. It's nice to have options :)

like image 134
Austin Thompson Avatar answered Nov 14 '22 22:11

Austin Thompson