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...
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:
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.
I was wondering if there is a plugin that allows me to jump directly to the test for the current class (Or create it if it doesn't exist).
I guess this should be based on the convention that the test project is named like the project being tested + "test" and the test class is named like the class being tester + "test".
A feature like that would really help in projects with many files and foldes, where scrolling the solution explorer to find the associated test project can be quite annoying.
how about NCrunch? This tool will show you, per method, which and how many tests are covering it:
I did manage to find a few extensions on visualstudiogallery.com, but ended up writing my own plugin for this. Its not perfect, but i does what I needed.
If anyone else would like, its available for free at testlocator.eqa.dk
In Visual Studio you can Shift+F12 on any class or method definition to find all references. Although the resulting list Studio is not very convenient, but a starting point. Using a tool like DevExpress CodeRush or ReSharper lets you sort and filter by namespace, project, file, etc.
If you happen to use ReSharper, it has a TestLinker plugin.
It does the job pretty well.
Basic shortcut: Ctrl+Alt+F7.
Goto Related Files is extended with navigation points to production/test classes.
New shortcuts ReSharper_GotoAllLinkedTypes and ReSharper_GotoLinkedTypesWithDerivedName (assignable via keyboard options) that jumps between linked types. In case of multiple linked types, a dedicated popup menu is shown, which can also be displayed in Find Results window.
If I'm looking at a method definition in Visual Studio (with Resharper) is there an easy way to find out what class it belongs to? (As of now, I've resorted to a text search in the "up" direction for the string "class".)
The Resharper command Go to containing declaration (ctrl + [) should do the trick
Edit:
Or if you have the navigation bar at the top of the code window enabled, that should display the type name. But I have that turned off, since I use keyboard navigation and the bar itself slows down Visual Studio.
You have files with more than one class in? That makes ponies sad...
Anyway, to actually answer, can't you just look at the navigation bar?
The best (direct) way specific to your question is PHeiberg's answer.
But if you ask this question I guess you don't know the File Structure window that can be enabled by ReSharper->Windows->File Structure or by shortcut Ctrl+Alt+F.
With that window you see always where you are in your file.
Aside from using ReSharper's File Structure and/or Go to Containing Declaration - options mentioned previously - there's also a tiny feature in ReSharper called Quick Documentation that in my view is better suited for this kind of task since it shows you method info in-place, without forcing you to navigate anywhere from the method you're on. Ctrl+Q, Esc, and you're done. It works on all kinds of symbols (not limited to methods), both on declarations and on usages.
For VS, right click on the function and select 'Go To Declaration'. (Ctrl + F12)
By default Visual Studio displays all members and its extension methods for a type in intellisense.
Sometimes I would like to hide the extension methods to make it easier to find the member I am actually looking for (especially when using Linq).
Is there a shortcut or another way to display only the members of a type in intellisense?
Not that I'm aware of - but one thing you might want to do is get rid of the using directive for System.Linq. At that point the extension method won't be accessible, and I believe it won't be offered by Intellisense.
Obviously that's no good if you want to use LINQ from one bit of code in a class, but not in another - but for classes which aren't using LINQ at all, it might help you.
In theory you could do this with the appropriate decorator attribute*, but googling this it seems it's bugged, with the fix awaiting a service pack presumably.
* [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
Perhaps you could try using something like resharper which filters the list of methods as you type. I find this helps me to quickly get to what I need. And it will do so without hiding useful extention methods
Visual Studio 2022 has this.
When Intellisense is displaying, you can toggle 'Show only Properties' and 'Show only Methods' (hold Ctrl to get click both).
If you want to only see the extension methods, you can toggle 'Show only Extension methods'.