Esempio n. 1
0
        public void GetTokenLength(SyntaxToken token, out int length, out bool onMultipleLines)
        {
            // here, we can't just add token's length since there is token that span multiple lines.
            var text = token.ToString();

            // multiple lines
            if (text.ContainsLineBreak())
            {
                // get indentation from last line of the text
                onMultipleLines = true;
                length          = text.GetTextColumn(_options.GetOption(FormattingOptions2.TabSize), initialColumn: 0);
                return;
            }

            onMultipleLines = false;

            // add spaces so far
            if (text.ContainsTab())
            {
                // do expansive calculation
                var initialColumn = _treeData.GetOriginalColumn(_options.GetOption(FormattingOptions2.TabSize), token);
                length = text.ConvertTabToSpace(_options.GetOption(FormattingOptions2.TabSize), initialColumn, text.Length);
                return;
            }

            length = text.Length;
        }
Esempio n. 2
0
        protected AbstractTriviaDataFactory(TreeData treeInfo, SyntaxFormattingOptions options)
        {
            Contract.ThrowIfNull(treeInfo);

            this.TreeInfo = treeInfo;
            this.Options  = options;

            UseTabs         = options.GetOption(FormattingOptions2.UseTabs);
            TabSize         = options.GetOption(FormattingOptions2.TabSize);
            IndentationSize = options.GetOption(FormattingOptions2.IndentationSize);

            _spaces = new Whitespace[SpaceCacheSize];
            for (var i = 0; i < SpaceCacheSize; i++)
            {
                _spaces[i] = new Whitespace(this.Options, space: i, elastic: false, language: treeInfo.Root.Language);
            }
        }