I don't know what I did, but the default behavior for the quick action brought up by Ctrl + '.' is now to qualify a referenced type with a namespace as opposed to adding a new using statement at the top of my source file. While this works, it is very annoying (especially when referencing the same namespace repeatedly in the same source file).
Example:
If I type ISomeType I now get a code suggestion like:
"Replace ISomeType with My.NameSpace.ISomeType"
Where what I would prefer is:
"{}+ Using My.Namespace"
I have been searching through various settings and options without any luck (note: This is occurring while editing C# / .cs files and not related to MVC/Razor [for which I have seen open bugs]).
Shutting down the IDE and restarting ended up fixing my issue. Very weird.
Related
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:
What I said is like this in C#
It's very annoying when I need to manually add all open for the type I use in F# source code.Especially When I am not very familiar with the reference I work with.
If I forget the namespace,I open the object browser ,type the class name I am using, wait 1 or 2 second let VS finish freezing and get the namespace I want.
All I want is something like open namespace tip.I have searched it for more than half hour and I can not even find anyone asked the similar question.
Or It's all my fault and I should remember all the namespace the type I am using when I am coding???
Use Visual F# Power Tools, which can be installed on Visual Studio via Extensions and Updates.
List of current features:
Auto-generating XmlDoc
Formatting document / Formatting selection
Navigation bar
Highlight references
Rename refactoring
Depth colorizer
NavigateTo
Syntax coloring
Folder organization
Find all references
Implement interface
Record stub generation
Union pattern match case generation
Resolve unopened namespaces
Gray out unused declarations
Gray out unused open declarations
Go to metadata
Task List comments
Generate references for F# Interactive
Navigate to source
Quick info panel
FsLinter integration
More details in the link above, and on the GitHub repo.
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.
I'm trying to get rid of a ton of unnecessary fully qualified types and instead throw in a using at the top of these classes.
I am not sure if there is some kind of batch that would go out and do this for me. Right now I have to use ReSharper and erase the redundant portion of a type and then of course ReSharper asks to throw in the missing using and that's how I am going through each class manually cleaning these up.
There's got to be a more automated way where I can run some process to go through all the project in this solution and do this for me ..just like I'm having to do manually with each line of code with ReSharper?
You should use Code Cleanup. To run on a single file, go to ReSharper | Tools | Cleanup code, select Full cleanup or create your own profile with Optimize 'using' directives and Shorten qualified references turned to Yes. Maybe Remove code redundancies should be turned to Yes also.
You can run Code cleanup on several files. To do it, select necessary files in Solution explorer, press right mouse button and run Code cleanup from popup menu.
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...