Add Roslyn analyzer for actor registration#1441
Merged
WhitWaldo merged 13 commits intodapr:release-1.16from Apr 9, 2025
Merged
Add Roslyn analyzer for actor registration#1441WhitWaldo merged 13 commits intodapr:release-1.16from
WhitWaldo merged 13 commits intodapr:release-1.16from
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 <ngruson@hotmail.com>
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 <ngruson@hotmail.com>
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 <ngruson@hotmail.com>
…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 <ngruson@hotmail.com>
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
WhitWaldo
reviewed
Apr 1, 2025
| private static readonly DiagnosticDescriptor DiagnosticDescriptorActorRegistration = new( | ||
| "DAPR0001", | ||
| "Actor class not registered", | ||
| "The actor class '{0}' is not registered", |
Contributor
There was a problem hiding this comment.
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 <whit.waldo@innovian.net>
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
…ed in a future release Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
…split out analyzers to separate classes and updated tests accordingly. Update to rule ID numbering and verbiage. Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Contributor
|
@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! |
This was referenced Sep 25, 2025
This was referenced Nov 10, 2025
This was referenced Nov 17, 2025
This was referenced Dec 15, 2025
This was referenced Jan 5, 2026
This was referenced Jan 12, 2026
This was referenced Jan 21, 2026
This was referenced Feb 2, 2026
This was referenced Feb 16, 2026
This was referenced Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: