diff --git a/src/EditorFeatures/CSharpTest/Wrapping/ChainedExpressionWrappingTests.cs b/src/EditorFeatures/CSharpTest/Wrapping/ChainedExpressionWrappingTests.cs index 155b9138ff35a9a6711780490c9f05baed2d8bc4..6f72356421407fbe4aa385b35001f23a0be006a4 100644 --- a/src/EditorFeatures/CSharpTest/Wrapping/ChainedExpressionWrappingTests.cs +++ b/src/EditorFeatures/CSharpTest/Wrapping/ChainedExpressionWrappingTests.cs @@ -278,8 +278,9 @@ public async Task TrailingLongWrapping2() }", @"class C { void Bar() { - the.quick.brown().fox.jumped().over - .the().lazy().dog(); + the.quick.brown().fox + .jumped().over.the().lazy() + .dog(); } }", @"class C { @@ -322,7 +323,7 @@ public async Task TrailingLongWrapping3() @"class C { void Bar() { the.quick.brown().fox.jumped().over.the().lazy() - .dog(); + .dog(); } }", @"class C { diff --git a/src/EditorFeatures/Core/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs b/src/EditorFeatures/Core/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs index 3334a02615ec38af996d84e4be5089b97fbdde67..a86ee3d04ecd2366f85e0ab2ea717a1f581829b3 100644 --- a/src/EditorFeatures/Core/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs +++ b/src/EditorFeatures/Core/Wrapping/ChainedExpression/ChainedExpressionCodeActionComputer.cs @@ -52,9 +52,9 @@ private class CallExpressionCodeActionComputer : /// /// The indent trivia to insert if we are trying to align wrapped chunks with the - /// start of the original chunk. + /// first period of the original chunk. /// - private readonly SyntaxTriviaList _indentAndAlignTrivia; + private readonly SyntaxTriviaList _firstPeriodIndentationTrivia; /// /// The indent trivia to insert if we are trying to simply smart-indent all wrapped @@ -80,7 +80,7 @@ private class CallExpressionCodeActionComputer : // (i.e. . name (arglist)). var firstPeriod = chunks[0][0]; - _indentAndAlignTrivia = new SyntaxTriviaList(generator.Whitespace( + _firstPeriodIndentationTrivia = new SyntaxTriviaList(generator.Whitespace( OriginalSourceText.GetOffset(firstPeriod.SpanStart).CreateIndentationString(UseTabs, TabSize))); _smartIndentTrivia = new SyntaxTriviaList(generator.Whitespace( @@ -128,8 +128,12 @@ private ImmutableArray GetWrapEdits(int wrappingColumn, bool align) var firstChunk = _chunks[0]; DeleteAllSpacesInChunk(result, firstChunk); - var indentationTrivia = align ? _indentAndAlignTrivia : _smartIndentTrivia; - var position = indentationTrivia.FullSpan.Length + NormalizedWidth(firstChunk); + var indentationTrivia = align ? _firstPeriodIndentationTrivia : _smartIndentTrivia; + + // Our starting position is at the end of the first chunk. That position + // is effectively the start of the first period, plus the length of the + // normalized first chuck. + var position = _firstPeriodIndentationTrivia.FullSpan.Length + NormalizedWidth(firstChunk); // Now, go to each subsequent chunk. If keeping it on the current line would // cause us to go past the requested wrapping column, then wrap it and proceed.