@@ -51,27 +51,28 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5151 private static async Task < Document > GetTransformedDocumentAsync ( Document document , Diagnostic diagnostic , CancellationToken cancellationToken )
5252 {
5353 var syntaxRoot = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
54- var indentationOptions = IndentationOptions . FromDocument ( document ) ;
54+ var settings = SettingsHelper . GetStyleCopSettings ( document . Project . AnalyzerOptions , cancellationToken ) ;
5555
5656 var enumMemberDeclaration = ( EnumMemberDeclarationSyntax ) syntaxRoot . FindNode ( diagnostic . Location . SourceSpan , getInnermostNodeForTie : true ) ;
57- var enumMemberDeclarationFirstToken = enumMemberDeclaration . GetFirstToken ( ) ;
58-
5957 var enumDeclaration = ( EnumDeclarationSyntax ) enumMemberDeclaration . Parent ;
6058
6159 var memberIndex = enumDeclaration . Members . IndexOf ( enumMemberDeclaration ) ;
6260 var precedingSeparatorToken = enumDeclaration . Members . GetSeparator ( memberIndex - 1 ) ;
6361
64- var parentIndentationSteps = IndentationHelper . GetIndentationSteps ( indentationOptions , enumDeclaration ) ;
65- var indentation = IndentationHelper . GenerateWhitespaceTrivia ( indentationOptions , parentIndentationSteps + 1 ) ;
66-
67- var replacements = new Dictionary < SyntaxToken , SyntaxToken > ( ) ;
62+ // determine the indentation for enum members (which is parent + 1 step)
63+ var parentIndentationSteps = IndentationHelper . GetIndentationSteps ( settings . Indentation , enumDeclaration ) ;
64+ var indentation = IndentationHelper . GenerateWhitespaceTrivia ( settings . Indentation , parentIndentationSteps + 1 ) ;
6865
66+ // combine all trivia between the separator and the enum member and place them after the separator, followed by a new line.
67+ var enumMemberDeclarationFirstToken = enumMemberDeclaration . GetFirstToken ( ) ;
6968 var sharedTrivia = TriviaHelper . MergeTriviaLists ( precedingSeparatorToken . TrailingTrivia , enumMemberDeclarationFirstToken . LeadingTrivia ) ;
7069
7170 var newTrailingTrivia = SyntaxFactory . TriviaList ( sharedTrivia )
7271 . WithoutTrailingWhitespace ( )
7372 . Add ( SyntaxFactory . CarriageReturnLineFeed ) ;
7473
74+ // replace the trivia for the tokens
75+ var replacements = new Dictionary < SyntaxToken , SyntaxToken > ( ) ;
7576 replacements [ precedingSeparatorToken ] = precedingSeparatorToken . WithTrailingTrivia ( newTrailingTrivia ) ;
7677 replacements [ enumMemberDeclarationFirstToken ] = enumMemberDeclarationFirstToken . WithLeadingTrivia ( indentation ) ;
7778
0 commit comments