Skip to content

Fix method class over-indentation under file-scoped namespaces#737

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-method-class-indent
Jul 13, 2026
Merged

Fix method class over-indentation under file-scoped namespaces#737
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-method-class-indent

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Under file-scoped namespaces the base indentation was only reset to empty for the first output builder (the one emitting the namespace declaration). Every subsequent top-level member kept the default one-level indent and was written as if it were nested inside a namespace { ... } block. Because the method class is always emitted after the other top-level members, its body was the most visible case, but any struct/enum emitted after the first was affected too.

The fix derives the base indent from Config.GenerateFileScopedNamespaces up front instead of resetting it only inside the (first-builder-only) emitNamespaceDeclaration branch in CloseOutputBuilder -> ForCSharp.


Added the regression test FileScopedNamespaceTest.MembersAfterFirstAreNotOverIndented covering a struct + enum + free function. No existing golden exercised file-scoped namespaces with more than one top-level output builder, so there is no golden churn.

Full ClangSharp.PInvokeGenerator.UnitTests suite passes (Failed: 0, Passed: 3725).

Under file-scoped namespaces the base indentation was only reset to empty for the first output builder (the one emitting the namespace declaration). Every subsequent top-level member -- including the method class, which is always emitted last -- kept the default one-level indent and was written as if nested inside a namespace block.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding merged commit 6b9bf5f into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the tannergooding-fix-method-class-indent branch July 13, 2026 14:34
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.

1 participant