-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix API Diff args + async #49164
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
Fix API Diff args + async #49164
Conversation
APICompat was exiting at the first time it needed to go async. This was because Commandline was treating the SetAction call as synchronous since it didn't accept a CancellationToken. Fix this and plumb basic cancellation. I also noticed that the usage of Option<T> was incorrect and corrected it to be consistent with the way we use in other tools.
| rootCommand.Options.Add(optionAttachDebugger); | ||
|
|
||
| rootCommand.SetAction(async (ParseResult result) => | ||
| rootCommand.SetAction(async (ParseResult result, CancellationToken cancellationToken) => |
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.
This is the only functional fix here. The rest is cleanup after a5fe497
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.
Pull Request Overview
This PR fixes the API diff tool’s async handling by plumbing a CancellationToken through the asynchronous call chain and correcting Option usage for consistency.
- Updated RunAsync methods to accept a CancellationToken and added early cancellation checks
- Improved Option initialization in command-line options to match other tools
- Adjusted the root command’s SetAction signature to support cancellation token propagation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/MemoryOutputDiffGenerator.cs | Added CancellationToken parameter and inserted cancellation checks in loops |
| src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/IDiffGenerator.cs | Updated interface to require a CancellationToken in RunAsync |
| src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/FileOutputDiffGenerator.cs | Added cancellation checks and passed CancellationToken to inner RunAsync calls |
| src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff.Tool/Program.cs | Updated command line option definitions and SetAction callback to accept a CancellationToken |
APICompat was exiting at the first time it needed to go async.
This was because Commandline was treating the SetAction call as synchronous since it didn't accept a CancellationToken. Fix this and plumb basic cancellation.
I also noticed that the usage of Option was incorrect and corrected it to be consistent with the way we use in other tools.