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.