I am looking for a Visual Studio add-in that would analyze the text around the cursor position and navigate to the corresponding class definition.
For example I have this XML file that is currently open:
<object id="abc" type="MyProject.Foo.Bar, MyProject"/>
If I put the cursor somewhere between the double quotes on the type attribute the add-in should obtain the string "MyProject.Foo.Bar, MyProject" and search for all projects and project references in the current solution for the given type and if it finds one, it should navigate to the class definition (or metadata if the source code is not available in the current solution).
If such add-in doesn't exist I would greatly appreciate some pointers that could help me writing one.
Well you could use the 'Code Definition Window' that comes with the VS2008 IDE. When you place your cursor, the Code Def window dynamically updates with the source code for that type. Works with regular source files.. don't have the IDE at hand to verify with XAML/XML
Also you could 'Jump to Symbol' key combo but you would need CodeRush Express add in for that. Shift+Ctrl+Q. More details here.
Use the Alt+G command in Visual Assist.
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:
If there are lots of projects in one solution and each of them has lots of .cs file.
Also, there might be one more classes in one file.
So, what I want to ask is: How can I find a file or a class quickly?
I really don't like use the ctrl+F every time.
Is there any plugin like if I click the CTRL+SHIFT+R it will open a window of show a class list or a file list and I can input the keyword what I'd like to find.
Then, when I double click the result, the file will be opened for me.
In VS2010 at least, there is the Navigate To feature. It indexes file names, classes, and methods for quick searching. Hit Ctrl+, (comma) to bring up the dialog:
Also, if you don't mind paying (and getting additional features), there is Visual Assist X and ReSharper, both of which I believe support VS2008/VS2010 and have source navigation features.
You can try out the "Productivity Power Tools" extension for VS2010.
It adds a new menu called "Solution Navigator", which has a search box with autosuggest, that enables searching your solution.
it has lots of other features and I highly recommend it.
In the Code Snippet Manager I chose "Language: Visual C#" and added a folder containing one .snippet file I created.
Then, when editing a .cs file, I try to insert a snippet using ctrl+k ctrl+x but my newly added folder does not show in the list.
I'm I missing something? Do you have to specifically tell IntelliSense which snippets you want to have shown in the list when trying to insert a snippet? I thought that was done by choosing "Language: Visual C#" in the Code Snippet Manager...
Thanks!
Does your folder (and the snippet, when you click on the folder) show up in the Code Snippets Manager? If not, then maybe it didn't get added correctly (or VS 2010 didn't parse the snippet successfully, or didn't recognize that the file was a valid snippet)? I believe the folder will only show up in the Code Snippets manager if VS2010 finds something it recognizes as a valid snippet, so if there are any parsing issues, there might be problems.
If the folder does show up correctly, then I also did notice that, when you hit Ctrl-K, Ctrl-X, unlike in Visual Studio 2008, newly added snippet folders appear to be sent to the bottom of the list instead of being sorted. In VS 2008, I was able to stick an underscore before the folder name (e.g. _Code Snippets) and have it show up on top. Not so, here. I realize this might be an idiotic suggestion, but maybe it's at the bottom of the list instead of sorted in with the rest? I know, I know, but I had to ask...
Barring that, maybe there is a caching issue with IntelliSense?
Not much of an answer, I know, but maybe it will jog someone's memory?
Oftentimes I want to bring up a system class in a source view, so that I can browse the properties and methods exposed by the class. Below is the screenshot of what I mean:
Srting from metadata http://img443.imageshack.us/img443/940/stringfrommetadata.png
Usually I do this by selecting the class name and pressing F12 (or right click>Go To Definition). However, if I haven't got it anywhere ready, i have type it up and then do Go To Definition. Most of the time I have to delete what I typed later on.
Is there a way to bring up this view without having to type the class name? The VS2010 Navigate To dialog doesn't support this.
EDIT: When I posted the question I didn't use any Visual Studio plugins. Now that I realised that I have full CodeRush license (thanks to StackOverflow promotion for users with 10K rep) I will accept answers that use CodeRush or Refactor!.
EDIT: At this stage I haven't really got anywhere with trying to answer this question. I am going to leave it open and let the bounty auto-award itself to Rory as he explained what's happening the best. In the meantime(schedule allowing) I will investigate doing this with DXCore as I think it should be possible.
The view you're looking at appears to have been built by some sort of analysis of the IL of the framework. Without knowing the type you intend to look at, no deconstruction can be done. Therefore I feel that, you are unlikely to find exactly what you have said you are looking for.
Allow me to suggest a few alternatives though.
Disclaimer: I work for DevExpress as a CodeRush Community Evangelist.
The Object Browser (Ctrl+Alt+J) This screen will load without attempting to show you any particular type, it will therefore be down to you to find the type in question. However all types are available and full search functionality is provided. once the type you're looking or is found, all members are listed and available.
Update: If you use the (Ctrl+K, Ctrl+R) shortcut to launch the object browser, then it will launch focused on the Search box. This is invaluable.
There are a number of CodeRush features which can prove useful when trying to locate code.
TabToNextReference (Tab) Whilst the caret is positioned within a type, strike the tab key and the next reference to that type will be located. More Details
References ToolWindow (Shift+F12) When activated the References ToolWindow will show you any references to the current type or member. This toolwindow can also be used to navigate said references. The References Toolwindow can be used in both on demand and Live mode. this allows you to have the window update as you navigate your code (via mouse or keyboard) and locate all references of any symbol the caret lands upon.
QuickNav (Ctrl+Shift+Q): This feature is closest in style to VS2010's NavigateTo feature. QuickNav will locate symbols matching whatever you type into it's filter box. This facility also supports Camel Case search. More details
QuickNav is also much more configurable than it's VS counterpart
Finally
Please also keep in mind that CodeRush is build upon the DXCore, a framework which allows users to create their own plugins for use alongside each other and CodeRush.
This framework has been repeatedly been leveraged by the community to add additional functionality. So even if you don't see any thing quite to your needs, consider suggesting something to the community by way of the forums or even contact me directly RoryB at DevExpress dot Com
I'm sure there's something we can do to help you out :)
I was not aware of that new "Navigate To" feature, but I used to use Reflector for this sort of things. The pro version offers some integration with Visual Studio (Right clicking the method and selecting "Open In .NET Reflector"). It will open the reflector window and won't show the code in the VS itself. You can watch the demo that shows this feature and some others.
This is not the best answer that I'd expect but is a good option to know.
There is no way that I know of to do this in Visual Studio 2010. However, you can do this in ReSharper via the 'navigate to' menu. I suggest you try the 30 day trial from them, then if you really do need this then purchase it.
A number of add-ins allow you to browse objects (though usually in an object-browser treeview manner rather than in a "header" file form - I believe Resharper, CodeRush and Visual Assist X all have variations on this theme).
However, one add-in to consider (as it's free) is the VS Productivity Power Tools. It adds a Solution Navigator window that gives a view onto your solution just like Solution Explorer, but (among other enhancements):
can search & filter the files listed, e.g. show only those files that are named Test.
can "expand" any file entry to show the types and members within it.
If you've ever used Eclipse, you've probably noticed the great keyboard shortcuts that let you hit a shortcut key combination, then just type the first few characters of a function, class, filename, etc. It's even smart enough to put open files first in the list.
I'm looking for a similar functionality for Visual Studio 2008. I know there's a findfiles plugin on codeproject, but that one is buggy and a little weird, and doesn't give me access to functions or classes.
Vs11 (maybe 2010 had it too) has the Navigate To... functionality which (on my machine) has the Ctrl+, shortcut.
By the way it understands capitals as camelcase-shortucts (eclipse does so too). For instance type HH to get HtmlHelper.
This isn't exactly the same as Eclipse from your description, but Visual Studio has some similar features out of the box (I've never used Visual Assist X, but it does sound interesting).
The Find ComboBox in the toolbar ends up being a sort of "Visual Studio command line". You can press Ctrl+/ (by default) to set focus there, and Visual Studio will insert an ">" at the beginning of the text (indicating that you want to enter a command instead of search). It even auto-completes as you type, helping you to find commands.
Anyway, to open a file from there, type "open <filename>". It will display any matching files in the drop down as you type (it pulls the list of files from the currently open solution).
To quickly navigate to a function, in the code editor press Ctrl+I to start an incremental search. Then just start typing until you find what you are looking for. Press Escape to cancel the search, or F3 to search again using the same query. As you are typing in the search query, the status bar in the lower left corner will contain what Visual Studio is searching for. Granted, this won't search across multiple files (I've never used Eclipse much, but that sounds like what it does from your description), but hopefully it will help you at least a little bit.
If anyone stumbles upon this thread:
There's a free plugin (created by me) for Visual Studio 2008 that mimics the Eclipse Ctrl+Shift+R Open Resource dialog (note, not the Open Type dialog). It works with any language and/or project type.
You can find it at Visual Studio Gallery.
Some of the neat features are available in Visual Assist X, though not all of them. I've asked on their forums, but they haven't appeared as yet. VAX gets updated regularly on a rough 4 week period for bug fixes and a new feature every couple of months.
If you are looking for an add-in like this to quickly navigate to source files in your project:
try the Visual Studio 2005/2008 add-in SonicFileFinder.
Resharper does this with the Ctrl-N keyword. Unfortunately it doesn't come for free.
Visual Studio doesn't have anything like this feature beyond Find.
Found this thread while searching for Eclipse's Ctrl+Shift+R, and after seeing the Visual Studio Gallery, found the DPack Tools (they are free, and no, I'm not endorsed in any way by them).
But it's exactly what I was searching:
- Alt+U -> File Browser (a la Eclipse Ctrl+Shift+R)
- Alt+M -> Code Browser (Method list in the actual class)
It has more features, but I'm happy with these ones.
I have been using biterScripting along with Visual Studio to do more flexible searching and manipulation.
It can search the entire workspace.
It can search within any project - EVEN IF THAT PROJECT IS NOT LOADED OR EVEN PART OF A WORKSPACE.
It can find things using regular expressions.
AND, ABOVE ALL, it can make bulk changes. For example, want to change the name of a class from CCustomer to CUser, I can do it in just a few command lines - Actually, I have written scripts for things like this I do often. I DON'T HAVE TO CLICK ON EACH INSTANCE AND MANUALLY DO THE CHANGE.
And, it is inexpensive ($0). I downloaded it from http://www.biterscripting.com .
I'm also comming from the Java Development side and was looking for the CTRL+T feature in the Visual Studio. The other answers refer to open file, but since in C# the class name and file name can be different this is not what i was looking for.
With the Class View or the Object Browser you can search for Objects and Classes
[View]->[Class View] or [View]->[Object]