Parameter usage highlighting

We got a great suggestion from VSLee in the community about parameter usage highlighting.  VSLee says:

When you look at a method
implementation, it is hard to see where a particular parameter is being
referenced, or if it is even being used at all.

When you click on or select a parameter,
you could highlight all of the places that parameter is referenced in a
function. Maybe used the marching ants instead to avoid confusion with
all of the other highlighting that is being done in other parts of the
You could turn off the highlighting whenever the cursor is not on a parameter, to prevent overstimulating the user.

First off, this bug was excellently presented to us.  Not only did
it present the problem succinctly, but it also provided a useful
proposal that considered the potential drawbacks that could be
involved.  It's far easier for us to consider suggestions when
they've already been so well fleshed out by the submitter.

So this sounded like a great idea to me when i read it.  We
already have a couple of features in VS2005 that provide similar
features.  The first is "find all references".  When invoked
on the declaration of a variable it will find all uses of that variable
in your code.  These results are presented in a list that you can
then iterate through.  The problem with this is that this feature
is not what we would call "code focused".  What do i mean by
that?  Well, we consider "code focused" development to mean that
the preferred way for the developer to interact with his program is
through... well... "code".  This may seem surprising to you. 
After all, how else could you interact with your program?  Well,
there are numerous ways.  There are things like Class View, Class
Designer, the WinForms designer, etc.   So a tool which
provides information in a separate mechanism from your code would not
necessarily be "code focused".  Why is being "code focused"
important to us?  Well, to put it simply, it's important to us
because so many of you have told us it's important to you.  You
live and breathe code and you're most comfortable within that

The second related feature that we have is the "code definition
window".   This is a "code focused" tool that will show you
the declaration of any symbol when your cursor is on any
reference.  So this is close to what VSLee asked for, in that we
show the information to you as you're looking at the code, except that
we're showing the definition, not the references.

I was looking for a small diversion today and so I spent around an hour
today with Kevin coding up this feature.  We decided to take it a
bit further.  So instead of just method parameter, we also just
work on variables as well.  It was a lot of fun, was surprisingly
easy to code up, and behaves quite nicely after our initial
implementation.  (I'll post pictures later when i can take some
screen caps from work).  You just put your cursor on an identifier
and after a 1/4 second delay you'll see all references highlighted in
the code (using a yellow highlighter-like background).  Why the
quarter-second delay?  Well, we've received a large amount of
feedback about the C# IDE UI being too "noisy" (i.e. too much
flash/glitz).  If we didn't have the delay, then you would start
seeing yellow highlighting flashing occurring as you navigated around
the screen.  We had the same problem with brace
highlighting.  The initial implementation was really distracting
for users because as they arrowed around their code they would keep
having things distracting them in their peripheral vision.  Often
they wouldn't even know what it was (since they'd move off the brace),
but would just get confused and unhappy.  To prevent that we use
the delay so you won't see the highlighting until you settle on single
place in the code.

I like the current implementation, however kevin
feels that it could use some work.  He feels that users will want
to click on variable, see all references highlighted, and then munge
the code around while the markers stay active.  This is something
that won't work with the current implementation because when you
navigate away from the current variable we're going clear all the
highlighting since you're no longer on a variable.  So he's trying
to come up with a simple and intuitive model where users can do things
like highlight (and clear highlighting) references so that you can
navigate around (using the cursor) without losing these visual
cues.  And, on top of that, he'd also like a model whereby you
could have all that and modify your code as well.  Of course, this
is much more difficult problem since it means we need to track code
across edits (which is a very E&C type thing), which makes the
whole model much more heavyweight and possibly more difficult to

What do you think?  Would you like to see the feature as VSLee
asked for it?  Or would you prefer something more extensive?

Unfortunately, because we're shutting down and are absolutely packed on
your schedule, this feature won't be making it in to VS2005. 
However, because it's such a nifty little enhancement that can provide
you with useful information within your code it's something i'm going
to push for inclusion when we start working on the next version.

Comments (7)
  1. Luke says:

    Sounds like a good idea & something i would use. Would love to see it as a powertoy if it can’t make the final release.

  2. JetBrains ReSharper (Visual Studio 2003 Add-in) has a similar feature called Highlight usages,

    I’ve been using ReSharper for over a year now and wouldn’t want to develop without it.

  3. It sounds a lot like the Google toolbar’s highlighting of search terms, which is a great feature. I’ve often used it to see where parameters and variables are used in code (browsing in a web CVS browser), because my IDE didn’t have the capability.

    I don’t think that this is something I would want all the time, or even all _that_ frequently. And I would want the highlighting to endure beyond while I have the parameter selected. So I’d prefer a system that let me choose what to highlight and when.

  4. WOW! You know, I just thought about this yesterday while doing some network coding.

    I find this to be very useful when doing socket programming where you have to deal with a lot of buffers and streams. I generally have a hard time keeping track of all of them.

    How about doing the highlighting just within a method. Also the ability to set your color preference would be great.

    This is definately an EXCELLENT suggestion!! Is there any way this can be done as a Add-In? I would love to code this in my spare time if your not working on it anymore.

  5. bleh says:

    If you have a "hard time" keeping track of socket code then either the code itself is bad or the socket interfaces are bad. Simplify it.

  6. Bleh – The code I am talking about is a bunch of the following:

    // Receive new Buddies Certificate

    byte[] buddyCertData = new byte[Convert.ToInt32(tokens[2], 10)];

    ns.Read(buddyCertData, 0, buddyCertData.Length);

    // Save the certificate

    FileStream fs = new FileStream(selected + ".cer", FileMode.Create);

    fs.Write(bufCertPublic, 0, bufCertPublic.Length);


    There are lots of these together in some functions in order to get data. So, if I want to find something pertaining to the buddyCertData, I want that highlighted so I can see it being used at the appropriate point. I tend to copy/paste code that i’ve written before and rework the parameters to save on retyping. But that lead to code inaccuracy on my part as I would forget to change a certain parameter. This tends to happen after you spend 30-40 hrs straight on the code. This tool Cyrus developed would really help me cut down on my ability to screw up and mistype code 🙂

    BTW. If you look at the code I just posted, there is a run-time bug in there. If you didn’t catch it, the fs.Write() function is using bufCertPublic instead of buddyCertData.

    See what i’m talking about now?

    What I generally do when I need lots of code of the same type is I create a macro so that with a keystroke I can get the code segment generated. But I didn’t do it this time (I don’t know why).

    I spent close to 3 hrs finding that bug above. With Cyrus’s tool I could have found that in a matter of minutes. This tool would also be useful for people debugging code that someone else has written.

    Good Job Cyrus. Hope we get to see this soon 🙂

  7. Timbo says:


    Any time you find yourself copypasting code and changing some parameters, a little flag should pop up with "Extract Method?" printed across it.

Comments are closed.

Skip to main content