-
Couldn't load subscription status.
- Fork 362
Add Roslyn analyzer for actor registration #1441
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
Conversation
- Introduced `Dapr.Actors` package reference (v1.15.0-rc01). - Added `Microsoft.CodeAnalysis.CSharp.Analyzer.Testing` package reference (v1.1.2). - Created `Dapr.Actors.Analyzers` and `Dapr.Actors.Analyzers.Test` projects. - Implemented `ActorRegistrationAnalyzer` to warn about unregistered actors. - Developed `ActorRegistrationCodeFixProvider` to suggest actor registration. - Added unit tests for both the analyzer and code fix provider. - Updated documentation for analyzer releases. - Enhanced test project with necessary references and utility methods. Signed-off-by: Nils Gruson <[email protected]>
Renamed `ActorRegistrationAnalyzer` to `ActorAnalyzer` and enhanced it to analyze JSON serialization options for actors. Updated the code fix provider to `ActorJsonSerializationCodeFixProvider` to enable JSON serialization when not set. Introduced new diagnostic `DAPR0002` for interoperability with non-.NET actors. Updated project references and added tests for the new functionality while improving code structure and readability. Signed-off-by: Nils Gruson <[email protected]>
Introduce a new diagnostic rule (DAPR0003) that warns users to call `app.MapActorsHandlers` for Dapr actors. Implemented in the `ActorAnalyzer` class with a corresponding code fix provider (`MapActorsHandlersCodeFixProvider`) to automatically add the call when needed. Updated `SupportedDiagnostics` to include DAPR0003 and added the `AnalyzeMapActorsHandlers` method for syntax tree analysis. Introduced `FindInvocation` to locate method calls in the syntax tree. Added tests in `ActorAnalyzerTests` and `MapActorsHandlersCodeFixProviderTests` to validate the new functionality, covering various scenarios. Updated `Utilities` and `VerifyAnalyzer` classes to include necessary assembly references for compatibility across .NET versions. Made minor adjustments to existing code and tests for consistency. Signed-off-by: Nils Gruson <[email protected]>
…otnet-sdk into 1426-ng-analyzer-actor
Simplify handling of createBuilderInvocation and buildInvocation by removing unnecessary nested checks. Improve code readability with clearer conditional blocks. Ensure the document is returned with the modified syntax root after changes. Signed-off-by: Nils Gruson <[email protected]>
| private static readonly DiagnosticDescriptor DiagnosticDescriptorActorRegistration = new( | ||
| "DAPR0001", | ||
| "Actor class not registered", | ||
| "The actor class '{0}' is not registered", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll likely need to revisit this in the future as there's consideration for facilitating cross-service actor invocation, so it might very well be the case that an actor is referenced that doesn't exist in the same service.
Signed-off-by: Whit Waldo <[email protected]>
Signed-off-by: Whit Waldo <[email protected]>
…ed in a future release Signed-off-by: Whit Waldo <[email protected]>
…split out analyzers to separate classes and updated tests accordingly. Update to rule ID numbering and verbiage. Signed-off-by: Whit Waldo <[email protected]>
|
@ngruson I've refactored your solution a bit to fit in with the current bits on 1.16 and to put the analyzers in separate files. Otherwise, this looks good to go. Thank you very much for your contribution! |
|
@holopin-bot @ngruson Thank you! Here's a digital badge as a small token of appreciation. |
|
Congratulations @ngruson, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cmbs0jgyd089207l1y5lw0ahe This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
Description
This PR adds a Roslyn analyzer that checks if actors are registered properly.
For every actor in the project, the analyzer checks if there's a corresponding
RegisterActorcall in the application setup.If there's no
AddActorscall yet, it will add it as well. The analyzer will look forWebApplication.CreateBuilderand adds the actor registration directly below it.Dapr.Actorspackage reference.Microsoft.CodeAnalysis.CSharp.Analyzer.Testingpackage reference (v1.1.2).Dapr.Actors.AnalyzersandDapr.Actors.Analyzers.Testprojects.ActorRegistrationAnalyzerto warn about unregistered actors.ActorRegistrationCodeFixProviderto suggest actor registration.Issue reference
This PR belongs to issue #1426.
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: