dlf
dlf

Reputation: 9383

ReSharper autocompletion bug? with lambda scratch arguments

I'm using ReSharper 9.2. Example code:

class Foo
{
   private int _someField;
   private int _someOtherField;

   public Foo()
   {
      Action<int, int> a = (_, __) => { };
   }
}

As soon as I type type the ',' after the '_', R# decides I must really mean _someField, and automatically inserts it. I have all three options (Symbol completion, Smart completion, and Import completion) unchecked under Options > Environment > IntelliSense > "Automatically complete single item with". But I suspect this feature is not the cause of the bug because there are 2 fields that begin with _, so there should be more than a single item in the suggestion list.

It also isn't due to _ being treated as a magic character; if I name the fields xSomeField and xSomeOtherField and call the scratch variable x, I get the same thing.

Is there any way to prevent this?

Upvotes: 1

Views: 52

Answers (1)

dlf
dlf

Reputation: 9383

Naturally I discovered workarounds on my own almost immediately after posting the question. Each is a compromise that means losing a bit of functionality elsewhere, so pick your poison:

  1. Options > Environment > IntelliSense > Autopopup > C#: Set both "Where value is expected" and "Letters and digits" to "Display but do not preselect"
  2. Options > Environment > IntelliSense > Completing Characters > C# > Do not complete on: Add ',' to the list

The bug seems to be that R# doesn't realize that, in this context, you are actually naming a new variable and instead applies its "where value is expected" behavior.

Upvotes: 1

Related Questions