How to select usage suggestion hint - visual-studio

When I type the name of a class without specifying the full namespace and the class is not made available by the using statements, Visual Studio guesses which class I mean and shows the fully namespaced class name in a hint.
For example:
If I click it it adds the necessary using statement.
How can I select that hint using the keyboard?

So it turns out that this actually a ReSharper feature (not something that is built into Visual Studio) and I can press Alt+Enter to select it.

Related

Visual Studio 2017: Disable Intellisense for CodeSnippets

I'm using Visual Studio 2017 Enterprise, Version 15.3.3
I looks like IntelliSense has some new features for code completion. On of this feature is, that a field name is automatically suggested when a type is written.
SpacePosition s.. // starting with s, Intellisense suggest "space", "position" and "spacePosition"
I like this feature in general but not for code snippets. Using a code snipped I have the problem, that the name of a literal is automatically replaced by IntelliSense after pressing tab (which is used for navigate to the next literal).
In my example I want to name the property "other" and then jump the the next literal inside the snippet. But because of IntelliSense, the property name is replaced by "spacePosition".
Is there any way to disable the IntelliSense feature inside code snippets?
I found a solution for the same problem in Visual Studio Code:
stackoverflow article but not for Visual Studio
Disable the name suggestions in Tools/Options/TextEditor/C#/IntelliSense. That's what is causing this nonsense. Seems MS realized later that they flipped coders up by adding that feature that changes old behaviour greatly without giving them a way to disable it. Now there is such a checkbox.
I nearly uninstalled this studio because of this lol. Not sure, may be it's a good feature, but i'm too used to Tab code snippets around, that I'm better without it.
How to: Manage Code Snippets
To access the Code Snippets Manager
1.) On the Tools menu, click Code Snippets Manager. Shortcut Ctrl+K,Ctrl+B
How to: Change snippet behavior
To change snippet behavior.
1.) Go to Tools > Options > Text Editor > IntelliSense > Snippet Behavior
2.) See images.
Now there has no such option to disable this intellisense feature inside code snippets, but you can try to click 'Esc' key after type 'other', then click 'Tab' key to jump to next literal, please check the following:
This actually works correctly in Visual Studio 2019 for classes if it is a class that is valid for the current context (i.e. Doesn't exist in a namespace not in the current class namespace or in the using statements for the file).
Here is my example snippet
Snippet Definition
Snippet Use
And here is an example where I use two different classes as the second snippet, one that is a valid class name and works to use tab to autocomplete, and one doesn't work because the class requires adding an additional namespace using statement that is currently missing from the file:
So I see two options.
Use the sucky to cancel any auto-complete logic.
Ensure you have the proper using statements. You can even add using statements to your snippet using the imports declaration:

Auto qualify name in visual studio 2013? Intellisense?

Is there a way to quickly "Auto qualify" a variable type declaration in Visual Studio 2013?
E.g. if I type:
Dim SomeExcel as New Application
is there a way to get the IDE to automatically fill in the namespace? like this:
Dim SomeExcel as New Microsoft.Office.Interop.Excel.Application
The IDE seems to be able to infer the namespace readily enough; if I hover over the type name it can tell me what namespace(s) contain the type.
It would be really useful to me to be able to change an old project from "short names" like Application to fully qualified names like Microsoft.Office.Interop.Excel.Application without having to find each one and type out the whole namespace.
Or, in the event of an ambiguous name, if it would give me the option to pick which namespace and it would fill it in. Similar to how if you use an undefined class it will warn you and give you the options to either automatically add the Imports statement or even create a class stub for you.
Since it will do all that for you automatically, and it will make suggestions and autocomplete methods/properties for an interface instance as you type, I would be surprised if there was not a quick way to have it convert "short names" to fully qualified names, but if there is - I can't seem to find it! I looked through the menu commands, and various right-click menus, and I looked on MSDN but couldn't find anything - but i'm not sure I'm using the right search terms.
Hoping someone with more experience might know how to do this or if this functionality doesn't exist.
No, nothing exists in Visual Studio to do that.
Doing so also confers no special advantages, as VS will tell you if you have an ambiguous reference automatically and give you the possibilities to resolve it.
When that happens, just click the icon that appears when you hover over it and select the correct namespace. VS will then qualify it with that namespace.
Here's an image of the icon:
And the resulting menu:
Granted, that is for C#, but VB usually works the same way.

Renaming Namespace in Visual Studio?

In my visual studio sharepoint 2010 visual web part project, while creating the project, I typed the name that I want, yet when it went to the class file for editing, the namespace code says:
namespace PDFLibrary.VisualWebPart1
The PDFLibrary is the name I put which is ok, but I want to rename VisualWebPart1 if possible.
Does anyone know how to do this? Please share if this is possible.
Thanks.
You can select the VisualWebPart part of the name and right click it, then select Refactor->Rename, or select that part and press Ctrl+R+R which should have the same effect.
You can also use "search and replace" in entire solution. Just search all "PDFLibrary.VisualWebPart1" in your solution and replace with your new string. This is what Refacor -> Rename does as well.

ReSharper: Rename namespace not available?

I'm trying to rename a namespace. For some reason, ReSharper isn't giving me the option to do so. I right click on it and choose Refactor, but everything except "Convert" is greyed out. I try the key combination CTRL R + R, and it says the command is unavailable. What am I doing wrong?
Here is documentation suggesting that what I am trying to do should work:
http://www.jetbrains.com/resharper/documentation/help20/Refactoring/renaming.html#renameNamespace
I'm using Visual Studio 2008 with R# 4.5
I have come across this before and the answer is very subtle. Do not select (eg by double clicking) the entire method name(or namespace if renaming a namespace). Instead, ensure the method name is deselected and place the caret over the method name.
eg
NOT this
When you select the Convert menu the items should now be available for methods, and 'Rename' will become available if you had the caret over a namespace.
In my mind this should be changed, it is not obvious.
Apparently, the way to do this now is via ReSharper => Refactor => Adjust Namespaces menu or open the Class View, right click on the namespace you wanted to rename and again select Refactor => Adjust Namespaces.
See also: Fastest way to update namespaces with ReSharper?
For what it's worth, I just had this problem. Closing Visual Studio and re-opening it fixed the problem for me. HTH.
This is an old issue but I just had this and perhaps know a workaround.
Since someone has commented just yesterday timing could not be more perfect.
Anyways,
I had the same issue and was finally able to do a rename refactoring on my namespace.
I chose one of the classes in my project and did the move to another namespace refactor.
Then I was able to go to another class and do the rename namespace refactor.
Perhaps a bug in Resharper that if the namespace is consistent throughout the class then it's disabled? Unlikely since this was reported as far back as 4.5...

How to automatically generate an implementor of an interface in Visual Studio?

In Eclipse I can create a class with stub methods auto-generated for an interface. Surely this works in Visual Studio somehow, but for the life of me, I can't figure out how...
Any thoughts?
Yes you can. Type the interface name as usual and look for a smart tag to pop underneath the interface name. Expand that and it will give you menu options for implementing the interface.
The keyboard shortcut for this is Control + ..
Here's a good article on the code refactoring functionality in Visual Studio 2005.
Refactoring C# Code Using Visual Studio 2005
Type the name of the interface and either right click it (using the smart tag), or, my personal favorite, press ctrl + point. (No need to reach for the mouse ;) ).
In vb.net you just write class name
implement interface [press enter here]

Resources