Поделиться через


More on autocomplete

Related to the questions around TAB and ENTER are some questions around the new “autocomplete on identifier”.

(I could swear I’ve blogged about this before, but I can’t seem to find it.)

In VS2002 / VS2003, if you type ‘foo.’, you get a completion list with members of ‘foo. Most people are happy about that most of the time.

What many users don’t realize is that they can bring up a completion list much more often than on dot. CTRL-SPACE is the default keybinding for Complete Word. If there’s an unambiguous match, it’ll complete it. Otherwise it’ll show the completion list. If the match is exact except for casing, then it’ll fix the casing. (That’s nice when you type Arraylist).

For Whidbey, we decided to bring the completion list up more often. We figured this would help you be more productive. Novice users aren’t sure what’s out there, and would appreciate the help. Even expert users (well, me) are known to mistype ‘namespace’ and ‘protected’. And none of us like to type more than is necessary.

We knew that putting keywords in the completion list was required. Without that, we’d keep trying to complete type & variable names whenever you type keywords. We would have liked to be really smart about only displaying the keywords that are legal at the time, but that turned out to be an extremely difficult problem. We ended up with doing a little bit of keyword filtering for Beta 1, but we may remove even that for Beta 2.

We originally experimented with showing the completion list whenever you were typing a name. So, suppose you had:

        Console.Write ();

And decided to switch to calling “WriteLine”. As soon as you hit ‘L’, we’d show a completion list.

It turned out to be extremely annoying. Every time you dismissed a completion list, it would pop up a moment later. If you ever wanted to type something that wasn’t in the list, you couldn’t.

We also experimented with having BACKSPACE show a completion list. It was also very annoying, and decided to cut it in the end.

Today, we automatically show the completion list in these situations:

  • If we have special knowledge. Autocomplete on ‘override’, ‘new’, and situations where an enum type is expected.
  • On dot, showing member lists.
  • On the first character in a name.

The last one is the result of all this experimentation.

There are a couple places where this behavior is annoying, however. They all come down to typing names that don’t already exist. One common pattern in C# 2.0 is creating a generic method that returns a parameterized type:

T Foo<T>() { }

 

When you type the first character, a completion list appears, but doesn’t include ‘T’. If you hit SPACE, we complete one ‘true’ or something. Some people find this extremely annoying.

Another case is just writing a statement before you declare the variables in the statement.

I described a similar issue with autocomplete on dot, as related to Generate Method Stub. The issue existed in VS2002 / VS2003, but now it’s more annoying because there’s more value in writing calls before the implementation.

We decided that perhaps the problem was that LPAREN, DOT, and SPACE were committing from the completion list. If we made completion a deliberate action, people wouldn’t ever be annoyed by automatic completion. We experimented with having only TAB or TAB and ENTER do completion. We got overwhelming feedback from dogfooders right away that they hated this behavior. I insisted that they try to build new habits, but they insisted back.

So today we have the behavior that just about every non-alphanumeric character will commit the completion list. ENTER and TAB have special behavior. As long as you’re typing something that we know about, you love the way we work. And when you type something we don’t know about, you hate it.

We don’t know how to make the experience good for all types of users, in all situations. We’ve gotten lots of feedback from users, all of it contradictory.

Right now we’re leaning to keeping the current behavior, but adding an option to restrict the completion commit keys to just TAB and ENTER. There’s already an option to disable autocomplete-on-identifier.

I hope that you’ll like the behavior we’ve selected by default. If you don’t like it, I hope that you’ll find the optional behavior that suits you.

 

Edit: See this ladybug issue. Some folks really don't like this behavior, although not everyone understands what the behavior is, exactly.

Comments

  • Anonymous
    August 30, 2004
    One thing that would be helpful for me (and maybe helpful for others, who knows?) is that if a var is in scope that matches the param name, go with that as the default. For instance, we pass around workspaceName as a string in many of our API's, yet as I'm typing the param to a method call, it's not there as my default.

    Such a feature would be nice since it helps reward developers that try to keep consistent names for the same kinds of params in their API's, IMHO. Not a huge deal, but it'd be nice :)
  • Anonymous
    August 30, 2004
    However Reshaper works is how Whidbey ought-to. it just rocks.
  • Anonymous
    August 31, 2004
    There are no correct defaults. The problem is that with all the ambiguities, a single user can hit cases where it bahaves incorrectly and then correctly, then incorrectly...

    For example, what's the use of having an generate method refactoring if your autocomplete won't let you type the name of a non-existant method without you going insane?

    I find that (currently hacking the registry) switching the completion chars to tab and enter do go a long way.

    But even so, if I have a feature that aannoys me 5% of the time that I'm typing in code, I'm going to disable it, even if the other 95% is great.

    Dropping me out of "the zone" is a lot bigger deal than reminding me what variables are currently in scope.
  • Anonymous
    August 31, 2004
    The comment has been removed
  • Anonymous
    September 02, 2004
    The comment has been removed
  • Anonymous
    September 02, 2004
    Oops, that should have been WYSIWYT. Where's auto-correct when you need it. :-)
  • Anonymous
    September 02, 2004
    Keith: the behavior around 'int?' is only like that because the nullable work came on so late before the Beta. There's no way I'd let that bug go out in the final release! Try to see the autocomplete behavior without that bug.

    As I said, when we made intellisense only complete on TAB, we got a lot of complaints from people who do want it to complete more often.

    The behavior you describe with m_ vs. m- exists in VS2002/VS2003 if you use an instance:

    this.m- <--- will complete on the wrong thing.

    If you look in Tools.Options.TextEditor.C#.IntelliSense, there is an option "Show completion list when an identifier is started". Is that enough to resolve the differences between the way different users work?
  • Anonymous
    September 04, 2004
    Ah, I guess I never type "this.m_". I always use just "m_" and I never run into this because "m-" doesn't cause the list to appear. As it is now I have configured the auto-completion list to not automatically appear. It was one of the Tools | Options check boxes. BTW, did you present a PDC session on debugging tips at either the '97 San Diego or '00 Orlando PDC? I learned a lot of good stuff from that talk. :-)
  • Anonymous
    September 05, 2004
    Keith: I did give a talk on the debugger in Orlando, but I don't remember the year. 2000 sounds right. I gave debugger talks at a series of conferences, and that was the worst (and last). That you liked the talk is really nice to hear!

    I've been toying with a presentation on the C# editor, but so far I haven't figured out what should go in it.

    Hmm, I'll ask...
  • Anonymous
    June 16, 2009
    PingBack from http://topalternativedating.info/story.php?id=11948