Skip to content

Emit single-file helper types below the method class instead of mid-file#738

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-singlefile-helper-functions
Jul 13, 2026
Merged

Emit single-file helper types below the method class instead of mid-file#738
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-singlefile-helper-functions

Conversation

@tannergooding

Copy link
Copy Markdown
Member

In single-file mode the deferred method class (Methods) was flushed after the generate-helper-types helper types, so with both a struct and functions the helpers were emitted between the struct and Methods -- in the middle of the file rather than at the top or bottom. Flush the deferred method class output builders before the helper types so the helpers join the shared namespace at the bottom, after all user content.

Multi-file mode is unchanged: the method-class builders are already written directly to their own files, so the relocated loops are a no-op there.

Added HelperTypesEmittedAfterMethodClass and HelperTypesEmittedAfterMethodClassFileScoped regression tests covering block-scoped and file-scoped single-file output with both a struct and a function, asserting the order struct -> Methods -> helper types with a single set of usings and no duplicate namespace.

Fixes #429

In single-file mode the deferred method class (`Methods`) was flushed after
the generate-helper-types helper types, so with both a struct and functions
the helpers were emitted between the struct and `Methods` -- in the middle of
the file rather than at the top or bottom. Flush the deferred method class
output builders before the helper types so the helpers join the shared
namespace at the bottom, after all user content.

Fixes dotnet#429

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 607877d into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-fix-singlefile-helper-functions branch July 13, 2026 14:45
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.

Specifying generated helper functions while in single-file mode injects the helper functions in the middle of the generated code

1 participant