|
| 1 | +# Roslyn Analyzers - Code JoyRide |
| 2 | + |
| 3 | +An example projects that includes Roslyn analyzers with code fix providers. Enjoy this template to learn from and modify analyzers for your own needs. |
| 4 | + |
| 5 | +## Agenda |
| 6 | + |
| 7 | +We will try to cover at least two of the following bullet points: |
| 8 | + |
| 9 | +- Quick Introduction to Compilers and Roslyn |
| 10 | +- Developing a Semantic Code Analyzer |
| 11 | +- Providing a Code Fix Provider for the Analyzer |
| 12 | + |
| 13 | +The workshop would be interactive and we do live coding. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- Some knowledge of programming 😁😜 |
| 18 | +- Laptop 💻 |
| 19 | +- [.NET Core](https://dotnet.microsoft.com/en-us/download) installed on your machine; see [all versions](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) for more information |
| 20 | +- Have your preferred IDE installed; |
| 21 | + - [JetBrains Rider](https://www.jetbrains.com/rider/download/) |
| 22 | + - [VS Code](https://code.visualstudio.com/download) with [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp), [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit) [Optional] |
| 23 | +- Clone the [CodeJoyRide repository from GitHub](https://github.com/shahab-the-guy/code-joy-ride) if you want to implement with us step by step |
| 24 | +- Last but not least, You 👩🏻💻👨🏻💻 |
| 25 | + |
| 26 | +## Content |
| 27 | +### CodeJoyRide.Fx.Analyzer |
| 28 | +A .NET Standard project with implementations of sample analyzers and code fix providers. |
| 29 | +**You must build this project to see the results (warnings) in the IDE.** |
| 30 | + |
| 31 | +- [MaybeSemanticAnalyzer.cs](SampleSemanticAnalyzer.cs): An analyzer that reports invalid usage of the `Maybe` type. |
| 32 | +- [MaybeCodeFixProvider.cs](SampleCodeFixProvider.cs): A code fix that replaces a `throw` statement with `Maybe.None`. The fix is linked to [MaybeSemanticAnalyzer.cs](./CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs). |
| 33 | + |
| 34 | +### CodeJoyRide.Api |
| 35 | +A project that references the CodeJoyRide.Fx analyzers. Note the parameters of `ProjectReference` in [CodeJoyRide.Api.csproj](CodeJoyRide.Api/CodeJoyRide.Api.csproj), they make sure that the project is referenced as a set of analyzers. |
| 36 | + |
| 37 | +### CodeJoyRide.Fx.Analyzer.Tests |
| 38 | +Unit tests for the CodeJoyRide analyzers and code fix provider. The easiest way to develop language-related features is to start with unit tests. |
| 39 | + |
| 40 | +## How To? |
| 41 | +### How to debug? |
| 42 | +- Use the [launchSettings.json](CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Properties/launchSettings.json) profile. |
| 43 | +- Debug tests. |
| 44 | + |
| 45 | +### How can I determine which syntax nodes I should expect? |
| 46 | + |
| 47 | +* Consider using https://sharplab.io/ and set the Result to `Szntax Tree` |
| 48 | +* On Visual Studio Code, consider installing the extension [CSharp Syntax Visualizer](https://marketplace.visualstudio.com/items?itemName=ypyl.syntax-visualizer-csharp) |
| 49 | +* Consider installing the Roslyn syntax tree viewer plugin [Rossynt](https://plugins.jetbrains.com/plugin/16902-rossynt/). |
| 50 | + * Unfortunately, based on my experience this one is not working on Rider's latest versions. |
| 51 | + |
| 52 | +### Learn more about wiring analyzers |
| 53 | +The complete set of information is available at [roslyn github repo wiki](https://github.com/dotnet/roslyn/blob/main/docs/wiki/README.md). |
0 commit comments