Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper (or Visual Studio) auto completion

I'm using VS 2010 with resharper. If I have a class called ConfigParserTests and then write

new ConfigParser(

the code will auto complete to

new ConfigParserTests()

which is not what I want. Any idea how to disable this nasty feature.

[Edit]

What is want is to write out

new ConfigParser()

without pressing "Esc". In this case I am using TDD so ConfigParser does not exist.

[/Edit]

I have been looking around in both the resharper and VS intellisense menus without finding anything helpful.

like image 666
BjartN Avatar asked Jan 31 '11 07:01

BjartN


2 Answers

Open Options window, navigate to Intellisense > Autopopup. You will see auto-complete options correspond to several cases and categorized according to language:

Changing Resharper auto-complete behaviour


As you see, you can select for each single case:

  • Do not display.

  • Display but do not preselect. (seems proper for your case)

  • Display and preselect. (default)


Different options may be selected in different cases or languages. For example, you can specify different behaviours in C#:

  • After dot

  • After 'new'

  • In doc comments

  • Letter and digits

  • Where value is expected

HTH

like image 132
mmdemirbas Avatar answered Oct 05 '22 09:10

mmdemirbas


It's not clear whether you're complaining about which class name it's filling in, or the parentheses. I'll address both.

If the class you're trying to use is in another namespace, and you haven't added the appropriate using yet, then the code completion is doing just what you would expect -- you told it which namespaces to use, and you didn't tell it to use the one with ConfigParser in it; so it uses the nearest match, as expected.

But ReSharper has shortcuts that can save you work by finding the class and adding the using for you. For this case, I would suggest that you look into the different Ctrl+Space options in ReSharper. You could write new cp <Ctrl+Alt+Space> and ReSharper will give you a pop-up menu asking whether you mean ConfigParser or ConfigParserTests. When you hit Enter to select the one you want, it will add the necessary using to the top of your file, and complete new ConfigParser() with the cursor between the parentheses.

(If the ConfigParser class doesn't exist yet, then that's one of the cases where you don't want code completion. Just type new ConfigParser and then hit Esc before typing your open paren.)

If your problem is that it adds a close paren, be aware that if you type ) ReSharper will not add a second close parenthesis -- it will recognize that you're typing a paren that it already added, so it will just move the cursor to the right. If for some reason you still don't want it to complete the open paren for you, @jdv-Jan de Vaan's answer explains where to change this preference.

like image 42
Joe White Avatar answered Oct 05 '22 09:10

Joe White