Example #1
0
 private int CurrentLineIndent(TextBuilder tb) {
     for (int i = tb.Length - 1; i >= 0; i--) {
         if (CharExtensions.IsLineBreak(tb.Text[i])) {
             return IndentBuilder.TextIndentInSpaces(tb.Text.Substring(i + 1), _options.TabSize);
         }
     }
     return 0;
 }
Example #2
0
        public FormattingScope(TextBuilder tb, TokenStream<RToken> tokens, int openBraceTokenIndex, RFormatOptions options, BraceHandler braceHandler) {
            Debug.Assert(tokens[openBraceTokenIndex].TokenType == RTokenType.OpenCurlyBrace);

            _options = options;
            _tb = tb;
            _previousIndentLevel = tb.IndentBuilder.IndentLevel;

            CloseCurlyBraceTokenIndex = FindMatchingCloseBrace(tokens, openBraceTokenIndex);

            StartingLineIndentSize = braceHandler.GetOpenCurlyBraceIndentSize(tokens[openBraceTokenIndex], tb, options);
            if (StartingLineIndentSize > 0) {
                tb.IndentBuilder.SetIndentLevelForSize(StartingLineIndentSize + _options.IndentSize);
            } else {
                tb.IndentBuilder.NewIndentLevel();
            }
        }
Example #3
0
 /// <summary>
 /// Determines indentation based on the leading whitespace in the current line.
 /// </summary>
 public static int GetLineIndentSize(TextBuilder tb, int position, int tabSize) {
     for (int i = position - 1; i >= 0; i--) {
         if (CharExtensions.IsLineBreak(tb.Text[i])) {
             return TextIndentInSpaces(tb.Text.Substring(i + 1), tabSize);
         }
     }
     return 0;
 }
Example #4
0
 public RFormatter(RFormatOptions options) {
     _options = options;
     _indentBuilder = new IndentBuilder(_options.IndentType, _options.IndentSize, _options.TabSize);
     _tb = new TextBuilder(_indentBuilder);
     _formattingScopes.Push(new FormattingScope(_indentBuilder));
 }
Example #5
0
 public RFormatter(RFormatOptions options) {
     _options = options;
     _indentBuilder = new IndentBuilder(_options.IndentType, _options.IndentSize, _options.TabSize);
     _tb = new TextBuilder(_indentBuilder);
 }
Example #6
0
 public BraceHandler(TokenStream<RToken> tokens, TextBuilder tb) {
     _tokens = tokens;
     _tb = tb;
 }
Example #7
0
        /// <summary>
        /// Given closing curly brace tries to find keyword that is associated
        /// with the scope and calculate indentation based on the keyword line.
        /// </summary>
        public int GetCloseCurlyBraceIndentSize(RToken closeCurlyBraceToken, TextBuilder tb, RFormatOptions options) {
            Debug.Assert(closeCurlyBraceToken.TokenType == RTokenType.CloseCurlyBrace);

            // Search stack for the first matching brace. Stack enumerates from the top down.
            var openCurlyBraceToken = _openBraces.FirstOrDefault(t => t.TokenType == RTokenType.OpenCurlyBrace);
            if (openCurlyBraceToken != null) {
                return GetOpenCurlyBraceIndentSize(openCurlyBraceToken, tb, options);
            }
            return 0;
        }
Example #8
0
        /// <summary>
        /// Given opening curly brace tries to find keyword that is associated
        /// with the scope and calculate indentation based on the keyword line.
        /// </summary>
        public int GetOpenCurlyBraceIndentSize(RToken openCurlyBraceToken, TextBuilder tb, RFormatOptions options) {
            Debug.Assert(openCurlyBraceToken.TokenType == RTokenType.OpenCurlyBrace);

            int keywordPosition = -1;
            if (_bracetoKeywordPositionMap.TryGetValue(openCurlyBraceToken, out keywordPosition)) {
                return IndentBuilder.GetLineIndentSize(tb, keywordPosition, options.TabSize);
            }
            return 0;
        }