dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.11k stars 4.04k forks source link

Find All in Visual studio based on Syntax tree #6618

Open FrankBakkerNl opened 9 years ago

FrankBakkerNl commented 9 years ago

It would be great to be able to use Roslyn to search for code patterns within Visual Studio. Kind of like what is possible in the Find / Find in Files dialog using regular expressions, but instead using the syntax tree and/or semantic model.

Currently we can do this by creating a custom diagnostic to search for specific code patterns, for ad-hoc searches however this is very cumbersome. It requires the creation of a new solution in a new Visual Studio instance and the code-debug cycle is not very efficient if you only want tho get the matches in your current working solution.

If instead you could write this code in an Immediate-like window inside Visual Studio if would get really easy to type simple searches without leaving the target solution. The results of the search would ideally be shown in a list view where you can click them to jump to the code. As a bonus, more developers would learn to use the Roslyn Api.

AdamSpeight2008 commented 9 years ago

An extension similar to Roslyn Quoter, would be helpful. Especially if it supported both C# and VB.

FrankBakkerNl commented 9 years ago

@AdamSpeight2008: Quoter would be nice to have as a Visual Studio extension, just like the syntax visualizer. This is however not what I mean here. (But not to hard to do I think)

What I would like to type in an Immediate-Like window is for instance AllNodes.OfType<MethodDeclarationSyntax>().Where(someFilter)

this will show a list of all the matching SyntaxNodes in the solution. If I then double click on an Item in the list I jump to that node in the code editor. I have started with a prototype which I intend to share shortly.

FrankBakkerNl commented 9 years ago

I published what I have right now https://github.com/FrankBakkerNl/IntelliFind It is a Visual Studio extension that basically does what I described above. The most important thing lacking right now is IntelliSense. Anyone willing to help out with that?

CyrusNajmabadi commented 1 month ago

@tmat this is possible now with your tool to access the rosolution solution/apis from within VS, right?

FrankBakkerNl commented 1 month ago

What tool do you mean @CyrusNajmabadi, does it do something similar to what I did here?

http://blog.frankbakker.net/2015/11/find-code-patterns-using-c-and-roslyn.html?m=1

Cool to see this still getting attention. I was pretty proud of my implementation at the time. It was just to cool to write these linq to roslyn queries and get live results in VS. To bad I never got to update it to newer VS versions.