Sort order of result for “Find All References” in

2020-06-30 07:54发布

问题:

I'm currently using Visual Studio 2010, but I don't think this is a version specific issue (think it was the exact same way in 2008 as well).

When I want to find out where in my solution some variable/function/whatever is used, I right-click it and select "Find All References". This gives me a long list in the Find Symbol Results view over all existing references. This list however, is quite messy. The results seem to be ordered by which file they are in, but it stops there. They are neither sorted by line number nor anything else slightly logical (at least that I can see...).

If I do the same kind of operation in e.g. Eclipse, I get a nice list where the search results are nicely ordered by file, then function and line number in the file. Is there a way I can achieve the same in Visual Studio (some preference to specify perhaps)? Or is this just one of those silly things where Visual Studio is completely hopeless? Or is there simply some brilliant sort ordering logic that I'm missing?

It's not like this is a very big problem, but it makes it quite much easier when you look through the references of a variable if it is in some kind of logical order...

Update:
Just to clarify: I know there are other add-ons and tools like ReSharper etc. that does these kind of things much better than Visual Studio. I'm interested if it is possible to "sanitize" the search-output from Visual Studio's existing "Find All References". And if not - what on earth is the logic behind their current sorting order (there has to be some logic, because I seem to get the same order in the results whenever I search for the same variable).

回答1:

I pinged the VS team on this one and it turns out that the reason for the wierdness is that Find All References is based on strings instead of numbers. This is why you see 1,2, 25, 3, 35, 4, etc... They are tracking it as a bug and it is slated to be fixed but the timeline is unknown.



回答2:

The workaround I am using is to create a collapsed region of 10,000 empty lines at the top to force the 6,000+ lines of code in this function (that I didn't write) to sort by line number correctly using the "Find All References" feature. I keep this region of empty lines in a separate text file and temporarily copy and paste them to the top of the source code when I am frustrated with how the search results are sorting.



回答3:

You could try using 'View Call Hierarchy' (Ctrl-K + Ctrl-T (VS2010)) for certain things instead. It sorts alphabetically by the looks of things. Or tools like CodeRush Express or ReSharper (not free) usually have nicer search facilities than those offered by visual studio.

http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/