tareqimbasher / NetPad

A cross-platform C# editor and playground.
MIT License
1.09k stars 56 forks source link

Implement Semantic Model #229

Open marknuzz opened 1 week ago

marknuzz commented 1 week ago

The new SyntaxTree visualizer looks great. I think it would be amazing if we had a Semantic Model as well. When developing analyzers using the Visual Studio semantic tree tool, the extension often breaks or stops working and then VS itself needs to be restarted. There are not a lot of great options for this.

A second reason that I think it would benefit NetPad, is that the new SyntaxTree UI is pretty clean and easy to work with (though there may be some room for improvement with showing additional properties the way VS does). So given that the SyntaxTree UI is good, people would choose to use Netpad for that reason over other tools (like VS, which isn't reliable). So it could make a lot of sense to have the semantic model as well as it's easier to develop analyzers when you have both available, and this could make NetPad possibly the 'best tool for the job'.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.semanticmodel?view=roslyn-dotnet-4.7.0

If it is something that is going to be a ton of work to do though, I wouldn't rush it if there are already other priorities. The Syntax Tree is a good enough step to where it should be easier for someone from the community to help complete it if there is enough demand.

tareqimbasher commented 1 week ago

Thank you for the feedback!

To make sure I understand your ask here, is the idea adding more metadata to the visualizer and offering additional functionality similar to: https://github.com/dotnet/roslyn/blob/main/docs/wiki/Syntax-Visualizer.md? Or are you asking to build a SemanticModel or a SyntaxTree yourself in code, and then basically "Dump()" that model and have it rendered in the visualizer?

marknuzz commented 1 week ago

More the first one.

See the section called Inspecting Semantics: https://github.com/dotnet/roslyn/blob/main/docs/wiki/Syntax-Visualizer.md#inspecting-semantics

The semantic model contains compilation information about symbols, classes, methods, etc, and not just syntax expressions.

marknuzz commented 1 week ago

I don't know how realistic it would be to have it in a UI that is updated in real time + fast however. It might not be realistically possible without it being a ton of work, and in that case I just wouldn't worry about it. It might be fine for small programs though

tareqimbasher commented 6 days ago

Thanks for the clarification. I'll review and let you know if this will be in scope!