daveaglick / LINQPad.CodeAnalysis

.NET Compiler Platform helpers and utilities for LINQPad - most of the functionality in this library has now been integrated into LINQPad directly
MIT License
43 stars 6 forks source link

Support for code fix with Roslyn #12

Open Kavignon opened 9 years ago

Kavignon commented 9 years ago

You could add the Roslyn Compiler platform within the code analysis plugin. Doing so, adding support for code fixes could be easy to do. All it would need is to create an analyzer and use it to provide code fixes. if you have some code fixes you'd like to do, we could talk it over this thread.

daveaglick commented 9 years ago

Thanks for your suggestion. I'd like to better understand what you're requesting. Right now, the LINQPad.CodeAnalysis plugin actually does use Roslyn. When you type CodeAnalysisUtil.DumpSyntaxTree(), what happens is that the text of the current query gets fed to Roslyn, which then parses it and returns a syntax tree which is visualized in the output window.

I'm also in the process of adding support for semantic analysis by feeding the syntax tree and all references used by the query into the Roslyn compiler (see the develop branch - this is a work in progress). Then you'll be able to request dumps of the ISymbol information for any node in the syntax tree as you can with the Visual Studio Syntax Visualizer.

I also have plans to integrate code fixes and analyzers once I get the semantic part done. Perhaps this is the aspect you were requesting? Any thoughts on how this should integrate within LINQPad?

Kavignon commented 9 years ago

That was what I meant. I was unsure that you were using Roslyn. That's my mistake for not looking deeper in the API that you built. As for analyzers and code fixers, I would mainly recommend to implement mostly good behaviors to follow while writing LINQ queries. I'm not sure what you mean by integration? Are you requesting help in the dev branch for implementing semantic analysis? I've no prior experience into that category of development but I could try.

daveaglick commented 9 years ago

No problem. I was mainly looking for feedback from a user interface perspective. For example, how should one apply a code fix to code in the LINQPad query? Would something like CodeAnalysisUtil.ApplyFix(...) do the trick, or should it be driven by a GUI? I'm also limited by the small set of extension points provided by LINQPad right now. I haven't worked out the best way to do this yet, so I'd love to hear any interface ideas you have.

Kavignon commented 9 years ago

Well, all libraries that I've seen try to automatically look at the abstract syntax tree and analyze the code through it. I think you could maybe benefit from proposing a solution where you implement a GUI which,after a user has complete to write his query in linq, pops up and ask him/her to validate code and shows possible errors/code fix that are applicable in the current situation. @daveaglick