Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 8, 2025

This PR fixes the method ordering in the Azure Management Generator to match the behavior of the old generator. Previously, the new generator was outputting sync methods first followed by async methods, but the old generator put async methods first.

Problem

The current generator produces code like this:

// Sync method first
public virtual Response<ZooResource> Get(CancellationToken cancellationToken = default) { ... }

// Async method second  
public virtual async Task<Response<ZooResource>> GetAsync(CancellationToken cancellationToken = default) { ... }

But the old generator produced:

// Async method first
public virtual async Task<Response<ZooResource>> GetAsync(CancellationToken cancellationToken = default) { ... }

// Sync method second
public virtual Response<ZooResource> Get(CancellationToken cancellationToken = default) { ... }

Solution

Updated method ordering to generate async methods before sync methods across all providers:

ResourceClientProvider: Fixed ordering in three locations:

  • Paging methods: Changed order from (sync, async) to (async, sync)
  • Update operations: Changed order from (sync, async) to (async, sync)
  • Other resource operations: Changed order from (sync, async) to (async, sync)

MockableResourceProvider: Fixed ordering in two locations:

  • Non-resource methods: Changed to add async method before sync method
  • Get methods: Changed to yield async method before sync method

ResourceCollectionClientProvider: Already correct - uses { true, false } pattern consistently.

Verification

Generated test projects now show async methods appearing first in all resource classes, collection classes, and mockable providers. All 51 existing tests continue to pass. Generated code compiles successfully with no functional changes, only ordering changes.

This change reduces the code diff when switching from the old generator to the new generator, making the migration smoother.

Fixes #51834.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] [Azure Mgmt Generator] The method order is changed [Azure Mgmt Generator] Fix method ordering to put async methods first Aug 8, 2025
@Copilot Copilot AI requested a review from ArcturusZhang August 8, 2025 09:48
Copilot finished work on behalf of ArcturusZhang August 8, 2025 09:48
…esourceProvider - async methods now come first

Co-authored-by: ArcturusZhang <[email protected]>
@Copilot Copilot AI changed the title [Azure Mgmt Generator] Fix method ordering to put async methods first [Azure Mgmt Generator] Fix method ordering to put async methods first across all providers Aug 8, 2025
@Copilot Copilot AI requested a review from ArcturusZhang August 8, 2025 10:06
Copilot finished work on behalf of ArcturusZhang August 8, 2025 10:06
@ArcturusZhang ArcturusZhang marked this pull request as ready for review August 11, 2025 02:48
@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 02:49
Copy link
Contributor

@Copilot Copilot AI left a 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 method ordering in the Azure Management Generator to ensure async methods appear before sync methods across all providers, matching the behavior of the old generator. Previously, the new generator was outputting sync methods first followed by async methods, which created unnecessary diffs when migrating from the old to new generator.

  • Fixed method ordering in ResourceClientProvider for paging, update, and other resource operations
  • Fixed method ordering in MockableResourceProvider for non-resource and get methods
  • Ensures async methods consistently appear before sync methods across all generated code

Reviewed Changes

Copilot reviewed 2 out of 10 changed files in this pull request and generated no comments.

File Description
ResourceClientProvider.cs Reordered method generation to put async methods before sync methods for paging operations, update operations, and other resource operations
MockableResourceProvider.cs Reordered method generation to put async methods before sync methods for non-resource methods and get methods

@live1206
Copy link
Member

/check-enforcer override

@live1206 live1206 merged commit 81aaf4a into main Aug 11, 2025
27 checks passed
@live1206 live1206 deleted the copilot/fix-51834 branch August 11, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Azure Mgmt Generator] The method order is changed
4 participants