Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Semantic Model #229

Open
marknuzz opened this issue Jul 3, 2024 · 4 comments
Open

Implement Semantic Model #229

marknuzz opened this issue Jul 3, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@marknuzz
Copy link

marknuzz commented Jul 3, 2024

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
Copy link
Owner

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
Copy link
Author

marknuzz commented Jul 3, 2024

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
Copy link
Author

marknuzz commented Jul 3, 2024

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
Copy link
Owner

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

hootanht added a commit to hootanht/NetPad that referenced this issue Aug 10, 2024
Fixes tareqimbasher#229

Add Semantic Model to SyntaxTree visualizer.

* **CodeController.cs**
  - Add a new endpoint to retrieve the semantic model for a given script.
  - Use `ICodeAnalysisService` to get the semantic model.
  - Return the semantic model as a JSON result.

* **CodeAnalysisService.cs**
  - Add a new method `GetSemanticModel` to retrieve the semantic model for a given code.
  - Use `CSharpCompilation` to get the semantic model.

* **ICodeAnalysisService.cs**
  - Add a new method `GetSemanticModel` to the interface.

* **syntax-tree-view.ts**
  - Add a new method to load the semantic model.
  - Update the UI to display semantic model information.
  - Cache the semantic model along with the syntax tree.

* **syntax-tree-view.html**
  - Add new elements to display semantic model information.
@tareqimbasher tareqimbasher added the enhancement New feature or request label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants