@@ -56,6 +56,8 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5656 private static async Task < Document > GetTransformedDocumentAsync ( Document document , Diagnostic diagnostic , CancellationToken cancellationToken )
5757 {
5858 var syntaxRoot = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
59+ var sourceText = await document . GetTextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
60+ var options = document . Project . Solution . Workspace . Options ;
5961 var whereToken = syntaxRoot . FindToken ( diagnostic . Location . SourceSpan . Start ) ;
6062 var precedingToken = whereToken . GetPreviousToken ( ) ;
6163 var endToken = syntaxRoot . FindToken ( diagnostic . Location . SourceSpan . End ) ;
@@ -65,11 +67,14 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
6567 var settings = SettingsHelper . GetStyleCopSettingsInCodeFix ( document . Project . AnalyzerOptions , syntaxRoot . SyntaxTree , cancellationToken ) ;
6668 var indentationTrivia = SyntaxFactory . Whitespace ( parentIndentation + IndentationHelper . GenerateIndentationString ( settings . Indentation , 1 ) ) ;
6769
70+ var precedingTokenEndOfLine = FormattingHelper . GetEndOfLineForCodeFix ( precedingToken , sourceText , options ) ;
71+ var endTokenEndOfLine = FormattingHelper . GetEndOfLineForCodeFix ( endToken , sourceText , options ) ;
72+
6873 var replaceMap = new Dictionary < SyntaxToken , SyntaxToken > ( )
6974 {
70- [ precedingToken ] = precedingToken . WithTrailingTrivia ( SyntaxFactory . CarriageReturnLineFeed ) ,
75+ [ precedingToken ] = precedingToken . WithTrailingTrivia ( precedingTokenEndOfLine ) ,
7176 [ whereToken ] = whereToken . WithLeadingTrivia ( indentationTrivia ) ,
72- [ endToken ] = endToken . WithTrailingTrivia ( RemoveUnnecessaryWhitespaceTrivia ( endToken ) . Add ( SyntaxFactory . CarriageReturnLineFeed ) ) ,
77+ [ endToken ] = endToken . WithTrailingTrivia ( RemoveUnnecessaryWhitespaceTrivia ( endToken ) . Add ( endTokenEndOfLine ) ) ,
7378 } ;
7479
7580 if ( afterEndToken . IsKind ( SyntaxKind . EqualsGreaterThanToken ) )
0 commit comments