/// <summary> /// Opens new formatting scope. Scope is opened when either /// code discovers open curly brace or when line break /// suppression is on. /// </summary> private void OpenFormattingScope() { Debug.Assert(_tokens.CurrentToken.TokenType == RTokenType.OpenCurlyBrace); if (IsInArguments()) { FormattingScope formattingScope = new FormattingScope(_indentBuilder); if (formattingScope.Open(_textProvider, _tokens, _options)) { _formattingScopes.Push(formattingScope); } } // If scope is empty, make it { } unless there is a line break already in it if (_tokens.NextToken.TokenType == RTokenType.CloseCurlyBrace && IsWhiteSpaceOnlyRange(_tokens.CurrentToken.End, _tokens.NextToken.Start)) { AppendToken(leadingSpace: _tokens.PreviousToken.TokenType == RTokenType.CloseBrace, trailingSpace: true); AppendToken(leadingSpace: false, trailingSpace: false); return; } else { if (_options.BracesOnNewLine) { _tb.SoftLineBreak(); } else if (!IsOpenBraceToken(_tokens.PreviousToken.TokenType)) { _tb.AppendSpace(); } } AppendToken(leadingSpace: false, trailingSpace: false); _tb.SoftLineBreak(); _tb.NewIndentLevel(); }