@@ -236,9 +236,7 @@ private protected override SyntaxNode MethodDeclaration(
236236
237237 return SyntaxFactory . MethodDeclaration (
238238 attributeLists : default ,
239- // Pass `withLeadingElasticMarker: true` to ensure method will space itself properly within the members it
240- // is added to.
241- modifiers : AsModifierList ( accessibility , modifiers , SyntaxKind . MethodDeclaration , withLeadingElasticMarker : true ) ,
239+ modifiers : AsModifierList ( accessibility , modifiers , SyntaxKind . MethodDeclaration ) ,
242240 returnType : returnType != null ? ( TypeSyntax ) returnType : SyntaxFactory . PredefinedType ( VoidKeyword ) ,
243241 explicitInterfaceSpecifier : null ,
244242 identifier : name . ToIdentifierToken ( ) ,
@@ -430,12 +428,13 @@ public override SyntaxNode GetAccessorDeclaration(Accessibility accessibility, I
430428 private protected override SyntaxNode SetAccessorDeclaration ( Accessibility accessibility , bool isInitOnly , IEnumerable < SyntaxNode > ? statements )
431429 => AccessorDeclaration ( isInitOnly ? SyntaxKind . InitAccessorDeclaration : SyntaxKind . SetAccessorDeclaration , accessibility , statements ) ;
432430
433- private static SyntaxNode AccessorDeclaration (
431+ private static AccessorDeclarationSyntax AccessorDeclaration (
434432 SyntaxKind kind , Accessibility accessibility , IEnumerable < SyntaxNode > ? statements )
435433 {
436- var accessor = SyntaxFactory . AccessorDeclaration ( kind ) ;
437- accessor = accessor . WithModifiers (
438- AsModifierList ( accessibility , DeclarationModifiers . None , SyntaxKind . PropertyDeclaration ) ) ;
434+ var accessor = SyntaxFactory
435+ . AccessorDeclaration ( kind )
436+ . WithModifiers (
437+ AsModifierList ( accessibility , DeclarationModifiers . None , SyntaxKind . PropertyDeclaration ) ) ;
439438
440439 accessor = statements == null
441440 ? accessor . WithSemicolonToken ( SemicolonToken )
@@ -1437,7 +1436,10 @@ public override SyntaxNode WithAccessibility(SyntaxNode declaration, Accessibili
14371436 modifiers = modifiers . WithIsStatic ( false ) ;
14381437 }
14391438
1440- var newTokens = Merge ( tokens , AsModifierList ( accessibility , modifiers ) ) ;
1439+ // We're updating the modifiers for something. We don't want to add elastic trivia in that case as
1440+ // we don't want the act of adding/removing/modifying modifiers to change the formatting of the parent
1441+ // construct.
1442+ var newTokens = Merge ( tokens , AsModifierList ( accessibility , modifiers , withLeadingElasticMarker : false ) ) ;
14411443 return SetModifierTokens ( d , newTokens ) ;
14421444 } ) ;
14431445 }
@@ -1647,7 +1649,10 @@ private SyntaxNode WithModifiersInternal(SyntaxNode declaration, DeclarationModi
16471649 }
16481650 }
16491651
1650- var newTokens = Merge ( tokens , AsModifierList ( accessibility , modifiers ) ) ;
1652+ // We're updating the modifiers for something. We don't want to add elastic trivia in that case as
1653+ // we don't want the act of adding/removing/modifying modifiers to change the formatting of the parent
1654+ // construct.
1655+ var newTokens = Merge ( tokens , AsModifierList ( accessibility , modifiers , withLeadingElasticMarker : false ) ) ;
16511656 return SetModifierTokens ( d , newTokens ) ;
16521657 } ) ;
16531658 }
@@ -1674,13 +1679,13 @@ private static SyntaxTokenList AsModifierList(
16741679 Accessibility accessibility ,
16751680 DeclarationModifiers modifiers ,
16761681 SyntaxKind kind ,
1677- bool withLeadingElasticMarker = false )
1682+ bool withLeadingElasticMarker = true )
16781683 => AsModifierList ( accessibility , GetAllowedModifiers ( kind ) & modifiers , withLeadingElasticMarker ) ;
16791684
16801685 private static SyntaxTokenList AsModifierList (
16811686 Accessibility accessibility ,
16821687 DeclarationModifiers modifiers ,
1683- bool withLeadingElasticMarker = false )
1688+ bool withLeadingElasticMarker = true )
16841689 {
16851690 using var _ = ArrayBuilder < SyntaxToken > . GetInstance ( out var list ) ;
16861691
0 commit comments