Add XPC3007: suggest type-safe Custom API handler overload#20
Merged
Conversation
When a Custom API declares AddRequestParameter/AddResponseProperty but registers with the action-based RegisterAPI<TService>(name, Action<TService>) overload, XPC3007 (Info) now suggests the type-safe RegisterAPI<TService>(name, nameof(TService.Handler)) overload that generates strongly-typed request/response DTOs, mirroring the type-safe image support for plugin steps. Includes a code fix that converts the lambda to nameof(...), after which XPC4005/XPC4006 guide the handler signature. Also: - Move the already-shipped Custom API rules (XPC3006/XPC4004/XPC4005/XPC4006) from AnalyzerReleases.Unshipped.md to Shipped.md under Release 1.4.1. - Mark the pending CHANGELOG entry as "v1.4.2 - Unreleased" and document the unreleased-entry and analyzer release-tracking conventions in CLAUDE.md. Co-Authored-By: Claude <noreply@anthropic.com> via Conducktor <conducktor@contextand.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds a new analyzer rule (XPC3007) and code fix to nudge Custom API registrations toward the type-safe RegisterAPI<TService>(name, nameof(...)) overload when request/response parameters are declared, and updates release/docs tracking to reflect shipped vs. unreleased analyzer rules.
Changes:
- Add XPC3007 analyzer + code fix to convert action-lambda registrations to
nameof(...)for typed Custom API handlers when parameters/properties are declared. - Add rule documentation for XPC3007 and expand unit tests to cover the new diagnostic and code fix.
- Update analyzer release tracking files and document changelog + analyzer-release conventions.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| XrmPluginCore/CHANGELOG.md | Adds v1.4.2 “Unreleased” entry documenting XPC3007. |
| XrmPluginCore.SourceGenerator/rules/XPC3007.md | New rule documentation and examples for XPC3007. |
| XrmPluginCore.SourceGenerator/Helpers/RegisterApiHelper.cs | Adds action-overload detection and lambda-method-name extraction helper. |
| XrmPluginCore.SourceGenerator/DiagnosticDescriptors.cs | Adds descriptor for new XPC3007 rule. |
| XrmPluginCore.SourceGenerator/CodeFixes/PreferTypedCustomApiHandlerCodeFixProvider.cs | New code fix provider converting lambda argument to nameof(...). |
| XrmPluginCore.SourceGenerator/Analyzers/PreferTypedCustomApiHandlerAnalyzer.cs | New analyzer that reports XPC3007 for action-overload registrations with declared params/properties. |
| XrmPluginCore.SourceGenerator/AnalyzerReleases.Unshipped.md | Moves previously shipped rules out; adds XPC3007 as unshipped. |
| XrmPluginCore.SourceGenerator/AnalyzerReleases.Shipped.md | Records XPC3006/XPC4004-6 as shipped in release 1.4.1. |
| XrmPluginCore.SourceGenerator.Tests/DiagnosticTests/CustomApiHandlerDiagnosticsTests.cs | Adds tests for XPC3007 diagnostic and code fix behavior. |
| CLAUDE.md | Documents new rule and release/changelog conventions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- GetActionMethodName: only extract the handler name when the lambda calls a method directly on the service parameter (s => s.Handle()), not on a different receiver (s => Other.Handle()) or a nested access (s => s.Foo.Handle()), so the code fix never offers a misleading nameof(TService.X). - CreateNameofExpression: parse the service type as a name so qualified (My.Namespace.Service) and generic (Service<T>) type names produce valid nameof syntax. This also fixes the shipped XPC3001 code fix, which shares the helper. - XPC3007 message: drop the hardcoded ".Handler" and recommend the typed overload with nameof(...) without implying a specific method name. - Tests + CHANGELOG updated accordingly. Co-Authored-By: Claude <noreply@anthropic.com> via Conducktor <conducktor@contextand.com>
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.
When a Custom API declares AddRequestParameter/AddResponseProperty but registers with the action-based RegisterAPI(name, Action) overload, XPC3007 (Info) now suggests the type-safe RegisterAPI(name, nameof(TService.Handler)) overload that generates strongly-typed request/response DTOs, mirroring the type-safe image support for plugin steps. Includes a code fix that converts the lambda to nameof(...), after which XPC4005/XPC4006 guide the handler signature.
Also: