Joe White’s Blog

Life, .NET, and Cats


ReSharper, day 15: The Ctrl+Space family

Welcome to day 15 of my 31 Days of ReSharper.

Yesterday, I talked about ReSharper’s version of Ctrl+Space. Today, I’ll cover the other two family members that ReSharper adds: Ctrl+Shift+Space and Ctrl+Alt+Space.

(Remember that Parameter Info, which used to be Ctrl+Shift+Space, is now Ctrl+P.)

Ctrl+Shift+Space: Filtered by expected type

Visual Studio’s regular Ctrl+Space (and ReSharper’s too) show every type from all the currently-imported namespaces. ReSharper also gives you a context-sensitive option, which only shows things of the right type — whatever type is expected at the current cursor position. You invoke the context-sensitive version with Ctrl+Shift+Space.

For example, if I type

Stream stream = new FileStream(fileName, FileMode.Open);
StreamReader reader = new StreamReader(

and then I hit Ctrl+Shift+Space, I’ll get a fairly short completion list, because it’s only showing things that could be a first parameter to the StreamReader constructor. stream will be one of the options in that list, and so will Stream.Null. And then, so are a bunch of static methods that return strings, since the StreamReader constructor has overloads that take strings.

They haven’t yet made this work for constructors. If I typed

Stream stream = new

and pressed Ctrl+Shift+Space, I would expect to see all the concrete descendant classes that I could use in this context. But I don’t; it just gives me “No suggestions”. Support tells me that the new scenario isn’t supported yet, but is already in the plans for a future release.

You know, though, this is one time I’d rather be working in Delphi. (Assuming, of course, that the Delphi IDE isn’t locking up for half a minute at a time every time I move the mouse, while it tries to do [and re-do and re-do] its “background” compilation — probably a vain hope, but a guy can dream.) That’s because Delphi’s Ctrl+Space is cooler yet: it’s context-sensitive, but it shows you not just expressions that are exactly the right type; it also shows you expressions you can use to get to the right type. E.g., if you’re in a context that expects an Integer, Delphi would show TForm instances in the list, because they have properties of type Integer (Width, Height, Constraints.MinWidth, etc.) You quickly get used to this, and I have trouble adapting to ReSharper’s much-more-restrictive context completion. Then again, maybe that’s why Delphi is so godawful slow in trying to build that list.

Update: If I create a new, empty method and press Ctrl+Shift+Space inside it, the autocompletion box pops up, even though there doesn’t seem to be a type to complete for. Ilya, one of the ReSharper developers, explains:

Ctrl+Shift+Space in empty method, or at any other place where statement is expected, e.g. between two other statements – it expects “void” type, so it shows just methods which doesn’t have return value.

Thanks, Ilya!

Ctrl+Alt+Space: types from all namespaces

Moving in a different direction, Ctrl+Alt+Space only shows type names — no properties, no methods, no constants; just types. But unlike Ctrl+Space, it looks in all namespaces, not just those you currently have usings for.

(Their documentation for Ctrl+Alt+Space says that it completes names of types within the current solution, but that’s not correct; it also completes types from any other referenced assemblies, so it works for things like FileStream and TestFixtureAttribute that come from Microsoft and/or third-party assemblies.)

So far, this sounds only vaguely interesting. Well, here’s the interesting part: when you select the type, ReSharper automatically adds the appropriate using directive if you don’t already have it.

(ReSharper has other features to add needed usings — in fact, I’m going to talk about one of them tomorrow — but I think I need to learn to use Ctrl+Alt+Space regularly: it promises to be faster and easier.)

Ctrl+Alt+Space requires that you type the first few characters of the type name before hitting the keystroke. I contacted Support to ask if this was on purpose, and they said yes, it was; because they’re building a list from all assemblies, they said it’d take too long if you hadn’t typed something to filter the list. Fair enough (although it’d be nice if they noted the reason in their documentation).

There are no responses to “ReSharper, day 15: The Ctrl+Space family” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2011. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS). Privacy policy