22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using System ;
56using System . Collections . Immutable ;
67using System . Threading ;
78using System . Threading . Tasks ;
@@ -45,7 +46,7 @@ private class SeparatedSyntaxListCodeActionComputer : AbstractCodeActionComputer
4546 /// ^
4647 /// |
4748 /// </summary>
48- private readonly SyntaxTrivia _singleIndentationTrivia ;
49+ private readonly Lazy < SyntaxTrivia > _singleIndentationTrivia ;
4950
5051 /// <summary>
5152 /// Indentation to use when placing brace. e.g.:
@@ -54,7 +55,7 @@ private class SeparatedSyntaxListCodeActionComputer : AbstractCodeActionComputer
5455 /// ^
5556 /// |
5657 /// </summary>
57- private readonly SyntaxTrivia _braceIndentationTrivia ;
58+ private readonly Lazy < SyntaxTrivia > _braceIndentationTrivia ;
5859
5960 /// <summary>
6061 /// Whether or not we should move the open brace of this separated list to a new line. Many separated lists
@@ -89,15 +90,15 @@ public SeparatedSyntaxListCodeActionComputer(
8990 var generator = SyntaxGenerator . GetGenerator ( OriginalDocument ) ;
9091
9192 _afterOpenTokenIndentationTrivia = generator . Whitespace ( GetAfterOpenTokenIdentation ( ) ) ;
92- _singleIndentationTrivia = generator . Whitespace ( GetSingleIdentation ( ) ) ;
93- _braceIndentationTrivia = generator . Whitespace ( GetBraceTokenIndentation ( ) ) ;
93+ _singleIndentationTrivia = new Lazy < SyntaxTrivia > ( ( ) => generator . Whitespace ( GetSingleIdentation ( ) ) ) ;
94+ _braceIndentationTrivia = new Lazy < SyntaxTrivia > ( ( ) => generator . Whitespace ( GetBraceTokenIndentation ( ) ) ) ;
9495 }
9596
9697 private void AddTextChangeBetweenOpenAndFirstItem (
9798 WrappingStyle wrappingStyle , ArrayBuilder < Edit > result )
9899 {
99100 result . Add ( wrappingStyle == WrappingStyle . WrapFirst_IndentRest
100- ? Edit . UpdateBetween ( _listSyntax . GetFirstToken ( ) , NewLineTrivia , _singleIndentationTrivia , _listItems [ 0 ] )
101+ ? Edit . UpdateBetween ( _listSyntax . GetFirstToken ( ) , NewLineTrivia , _singleIndentationTrivia . Value , _listItems [ 0 ] )
101102 : Edit . DeleteBetween ( _listSyntax . GetFirstToken ( ) , _listItems [ 0 ] ) ) ;
102103 }
103104
@@ -124,7 +125,7 @@ private SyntaxTrivia GetIndentationTrivia(WrappingStyle wrappingStyle)
124125 {
125126 return wrappingStyle == WrappingStyle . UnwrapFirst_AlignRest
126127 ? _afterOpenTokenIndentationTrivia
127- : _singleIndentationTrivia ;
128+ : _singleIndentationTrivia . Value ;
128129 }
129130
130131 private string GetBraceTokenIndentation ( )
@@ -270,7 +271,7 @@ private ImmutableArray<Edit> GetWrapLongLinesEdits(
270271 using var _ = ArrayBuilder < Edit > . GetInstance ( out var result ) ;
271272
272273 if ( _shouldMoveOpenBraceToNewLine )
273- result . Add ( Edit . UpdateBetween ( _listSyntax . GetFirstToken ( ) . GetPreviousToken ( ) , NewLineTrivia , _braceIndentationTrivia , _listSyntax . GetFirstToken ( ) ) ) ;
274+ result . Add ( Edit . UpdateBetween ( _listSyntax . GetFirstToken ( ) . GetPreviousToken ( ) , NewLineTrivia , _braceIndentationTrivia . Value , _listSyntax . GetFirstToken ( ) ) ) ;
274275
275276 AddTextChangeBetweenOpenAndFirstItem ( wrappingStyle , result ) ;
276277
@@ -317,7 +318,7 @@ private ImmutableArray<Edit> GetWrapLongLinesEdits(
317318
318319 if ( this . Wrapper . ShouldMoveCloseBraceToNewLine )
319320 {
320- result . Add ( Edit . UpdateBetween ( itemsAndSeparators . Last ( ) , NewLineTrivia , _braceIndentationTrivia , _listSyntax . GetLastToken ( ) ) ) ;
321+ result . Add ( Edit . UpdateBetween ( itemsAndSeparators . Last ( ) , NewLineTrivia , _braceIndentationTrivia . Value , _listSyntax . GetLastToken ( ) ) ) ;
321322 }
322323 else
323324 {
@@ -396,7 +397,7 @@ private ImmutableArray<Edit> GetWrapEachEdits(
396397 using var _ = ArrayBuilder < Edit > . GetInstance ( out var result ) ;
397398
398399 if ( _shouldMoveOpenBraceToNewLine )
399- result . Add ( Edit . UpdateBetween ( _listSyntax . GetFirstToken ( ) . GetPreviousToken ( ) , NewLineTrivia , _braceIndentationTrivia , _listSyntax . GetFirstToken ( ) ) ) ;
400+ result . Add ( Edit . UpdateBetween ( _listSyntax . GetFirstToken ( ) . GetPreviousToken ( ) , NewLineTrivia , _braceIndentationTrivia . Value , _listSyntax . GetFirstToken ( ) ) ) ;
400401
401402 AddTextChangeBetweenOpenAndFirstItem ( wrappingStyle , result ) ;
402403
@@ -419,7 +420,7 @@ private ImmutableArray<Edit> GetWrapEachEdits(
419420
420421 if ( _shouldMoveCloseBraceToNewLine )
421422 {
422- result . Add ( Edit . UpdateBetween ( itemsAndSeparators . Last ( ) , NewLineTrivia , _braceIndentationTrivia , _listSyntax . GetLastToken ( ) ) ) ;
423+ result . Add ( Edit . UpdateBetween ( itemsAndSeparators . Last ( ) , NewLineTrivia , _braceIndentationTrivia . Value , _listSyntax . GetLastToken ( ) ) ) ;
423424 }
424425 else
425426 {
0 commit comments