Parameter usage highlighting

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

Problem:

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.

Solution:

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
code. 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
environment.

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
understand.

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

  • Anonymous
    May 06, 2005
    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.
  • Anonymous
    May 06, 2005
    JetBrains ReSharper (Visual Studio 2003 Add-in) has a similar feature called Highlight usages, http://www.jetbrains.com/resharper/features/productivity.html

    I've been using ReSharper for over a year now and wouldn't want to develop without it.
  • Anonymous
    May 07, 2005
    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.
  • Anonymous
    May 07, 2005
    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.
  • Anonymous
    May 07, 2005
    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.
  • Anonymous
    May 07, 2005
    The comment has been removed
  • Anonymous
    May 09, 2005
    Sushant:

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