C#: Add MinimumViableSpacingVisitor for AutoFormat pipeline#7062
Merged
knutwannheden merged 1 commit intomainfrom Mar 19, 2026
Merged
C#: Add MinimumViableSpacingVisitor for AutoFormat pipeline#7062knutwannheden merged 1 commit intomainfrom
MinimumViableSpacingVisitor for AutoFormat pipeline#7062knutwannheden merged 1 commit intomainfrom
Conversation
…ormat pipeline
Recipes that synthesize new AST nodes with Space.Empty everywhere produce
unparseable printed output (e.g. "publicMyException():base(){}"), causing
the WhitespaceReconciler to bail and return unformatted trees.
The MinimumViableSpacingVisitor runs as the first step of RoslynFormatter.Format()
and inserts the minimum whitespace needed to keep tokens separated:
- Modifiers: public static → not publicstatic
- Keywords + identifiers: class Foo, void Bar, return expr, throw expr, etc.
- using/namespace directives
- Property declarations
- new + type, await + expr, yield return/break + expr
- foreach in + iterable
- Constructor initializer (: base/this)
- Class extends/implements (: BaseClass)
It does NOT handle indentation or stylistic formatting — Roslyn handles that.
MinimumViableSpacingVisitor for AutoFormat pipeline
MinimumViableSpacingVisitor for AutoFormat pipelineMinimumViableSpacingVisitor for AutoFormat pipeline
knutwannheden
added a commit
that referenced
this pull request
Mar 19, 2026
…ormat pipeline (#7062) Recipes that synthesize new AST nodes with Space.Empty everywhere produce unparseable printed output (e.g. "publicMyException():base(){}"), causing the WhitespaceReconciler to bail and return unformatted trees. The MinimumViableSpacingVisitor runs as the first step of RoslynFormatter.Format() and inserts the minimum whitespace needed to keep tokens separated: - Modifiers: public static → not publicstatic - Keywords + identifiers: class Foo, void Bar, return expr, throw expr, etc. - using/namespace directives - Property declarations - new + type, await + expr, yield return/break + expr - foreach in + iterable - Constructor initializer (: base/this) - Class extends/implements (: BaseClass) It does NOT handle indentation or stylistic formatting — Roslyn handles that.
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.
Summary
MinimumViableSpacingVisitorthat ensures minimum token separation in the C# LST so printed output is parseableRoslynFormatter.Format()as the first pipeline step, before printingSpace.Emptyeverywhere when synthesizing new nodes — the visitor ensurespublicvoidbecomespublic void,newSystem.Exceptionbecomesnew System.Exception, etc.Token separation handled:
public static finalnotpublicstaticfinal): base())return,throw,new,await,yield return/yield breakusing/namespacedirectivesforeachin+ iterableDesign:
SpacewhenIsEmpty— never touches existing whitespaceTest plan
MinimumViableSpacingTestscovering all handled cases