views:

450

answers:

2

I have a problem with a newly installed Visual Studio 2008 (new pc) and ReSharper 4.5.

Edit: Issue opened at: http://www.jetbrains.net/jira/browse/RSRP-107956.


I have the following code:

public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
    where TValue: new()
{
    #region Parameter Validation

    if (ReferenceEquals(null, key))
        throw new ArgumentNullException("key");

    #endregion

    TValue result;
    if (dictionary.TryGetValue(key, out result))
        return result;

    result = new <-- problem here
    dictionary.Add(key, result);
    return result;
}

The line marked as the problem is where I'm having problems.

When I type this (| marks the point of my cursor):

result = new |

then I get an intellisense dropdown with TValue in it, and it is selected.

No matter what I type now, this is what I end up with:

result = new _  (|);

again, | marks the cursor position. There are a couple of problems here:

  1. Regardless of what I type, a tab-character is inserted after the underscore, not two spaces as I had to use above.
  2. I've turned off the addition of parenthesis and brackets on completion, but they're still added for this particular construct
  3. It seems to be impossible to get ReSharper to insert the type selected, it just adds an underscore instead (no, the underscore is not my way of saying "type goes here", it expands to exactly what I showed above, without the type, but with an underscore + Tab-character instead)

Keys I've tried hitting when the intellisense is up:

  • Space (difference: parenthesis looks like this: ( |), ie. a space added)
  • Tab
  • Enter
  • ( - that is, opening parenthesis
  • T+any of the above (ie. type out the first letter of TValue and hope that helps, which it doesn't)

The only thing that "helps" is if I hit one of the keys that switches to the fuller intellisense dropdown, like the default Alt-Right, then it just adds lots more things I can select, still has TValue selected, but now if I hit Enter or Tab, the code is expanded correctly.

Does anyone know what I need to tweak?


Edit: Before I posted, I thought about the method and decided that the parameter validation there is probably not needed, so I took it away, and lo and behold, now it auto-completes correctly.

Is this just a(nother) bug in ReSharper?

Note that if I write the code correctly on that line, ie. write TValue instead of the underscore, the project builds.


Edit: Note, there are no live templates in ReSharper that are enabled, that was the first thing I disabled, just to test if there was a weird template that overrode my selection.

+1  A: 

Hello, I can confirm this behaviour. I get exactly the same results.

For me, it helps to enter two chars 'TV', then intellisence (Tab or Ctrl+Space) will expand to TValue(|). However it is not working when I type 'new' and straight on 'TV'. Aftern 'new' I have to press Esc ... a strange behaviour, indeed ...

UPDATE: it is the region that leads to this problem ... removing the region (only the two #region keywords - not the if-clause) helps me.

tanascius
Doesn't matter if I type the whole thing, as long as the "smart" ReSharper intellisense dropdown is in use, it doesn't work as expected. I'll send a bugreport to JetBrains.
Lasse V. Karlsen
I've posted a question to them, I'll report back what I find. Since I wanted to know if it was just me or not, I'll mark your reply as the accepted answer since you confirmed my suspicions that it's probably a bug of some sort.
Lasse V. Karlsen
And you're sort of right about the region, removing it makes the auto-complete select TValue, but it again adds the parenthesis, which I have explicitly turned off. But it's a step forward, and one to the side to boot. Thanks.
Lasse V. Karlsen
+2  A: 

I've been a ReSharper user since version 1.5, and I've noticed a certain pattern. First they support a feature of C#, then they support it fairly well, then they support it well except for edge cases, and finally they support it well except for rare bugs.

They're at step 2, or maybe 3, with generics. They've reached the point where they know inside of GetOrCreate that TValue is a type parameter, and they even now know it has a new() constraint, and so should be considered to be a type with a constructor as far as completion after "new". But they seem to have a little bug as to actually making the feature work smoothly.

Please do report it to them, so they can get to step 4, hopefully before the release of C# 4.0, with covariance and contravariance sends them back to step 2.

John Saunders
To be honest, I'm about this close >< to ditching ReSharper permanently. It seems that every time I re-test it, and find lots of cool new features, there's loads of small annoyances that just makes me irritable about the whole thing. Since I also have a license for Refactor! Pro from DevExpress, I'm contemplating just shelling out for CodeRush as well. As you say, it seems they always have some part of ReSharper that is at step 2.
Lasse V. Karlsen
Yeah, but I can also say that, since version 1.5, they've consistently improved. More so when they're getting high quality bug reports. More than just "it's too slow" or "it takes too much memory". I've seen them actually _fix_ some of the bugs I've reported, and I've seen them implement my suggestions. I'm one of those who suggested solution-wide analysis, for instance.
John Saunders
I posted a fairly detailed copy of the question I asked here, so hopefully they'll be able to fix it.
Lasse V. Karlsen