@@ -57,12 +57,14 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5757 private static async Task < Document > GetTransformedDocumentAsync ( Document document , Diagnostic diagnostic , CancellationToken cancellationToken )
5858 {
5959 var syntaxRoot = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
60+ var text = await document . GetTextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
61+ var options = document . Project . Solution . Workspace . Options ;
6062 var settings = SettingsHelper . GetStyleCopSettingsInCodeFix ( document . Project . AnalyzerOptions , syntaxRoot . SyntaxTree , cancellationToken ) ;
61- var newLine = FormattingHelper . GetNewLineTrivia ( document ) ;
6263
6364 var constructorInitializer = ( ConstructorInitializerSyntax ) syntaxRoot . FindNode ( diagnostic . Location . SourceSpan ) ;
6465 var constructorDeclaration = ( ConstructorDeclarationSyntax ) constructorInitializer . Parent ;
6566
67+ var newLine = FormattingHelper . GetEndOfLineForCodeFix ( constructorDeclaration . GetFirstToken ( ) , text , options ) ;
6668 var newConstructorDeclaration = ReformatConstructorDeclaration ( constructorDeclaration , settings . Indentation , newLine ) ;
6769
6870 var newSyntaxRoot = syntaxRoot . ReplaceNode ( constructorDeclaration , newConstructorDeclaration ) ;
@@ -110,12 +112,19 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
110112 }
111113
112114 var syntaxRoot = await document . GetSyntaxRootAsync ( fixAllContext . CancellationToken ) . ConfigureAwait ( false ) ;
115+ var sourceText = await document . GetTextAsync ( fixAllContext . CancellationToken ) . ConfigureAwait ( false ) ;
116+ var options = document . Project . Solution . Workspace . Options ;
113117 var settings = SettingsHelper . GetStyleCopSettingsInCodeFix ( document . Project . AnalyzerOptions , syntaxRoot . SyntaxTree , fixAllContext . CancellationToken ) ;
114- var newLine = FormattingHelper . GetNewLineTrivia ( document ) ;
115118
116119 var nodes = diagnostics . Select ( diagnostic => syntaxRoot . FindNode ( diagnostic . Location . SourceSpan ) . Parent ) ;
117120
118- return syntaxRoot . ReplaceNodes ( nodes , ( originalNode , rewrittenNode ) => ReformatConstructorDeclaration ( ( ConstructorDeclarationSyntax ) rewrittenNode , settings . Indentation , newLine ) ) ;
121+ return syntaxRoot . ReplaceNodes (
122+ nodes ,
123+ ( originalNode , rewrittenNode ) =>
124+ {
125+ var endOfLineTrivia = FormattingHelper . GetEndOfLineForCodeFix ( originalNode . GetFirstToken ( ) , sourceText , options ) ;
126+ return ReformatConstructorDeclaration ( ( ConstructorDeclarationSyntax ) rewrittenNode , settings . Indentation , endOfLineTrivia ) ;
127+ } ) ;
119128 }
120129 }
121130 }
0 commit comments