Exemple #1
0
        internal AbstractFormattingResult(
            TreeData treeInfo,
            TokenStream tokenStream,
            TextSpan formattedSpan)
        {
            this.TreeInfo      = treeInfo;
            this.TokenStream   = tokenStream;
            this.FormattedSpan = formattedSpan;

            _lazyChanges = new CancellableLazy <IList <TextChange> >(CreateTextChanges);
            _lazyNode    = new CancellableLazy <SyntaxNode>(CreateFormattedRoot);
        }
            public StructuredTrivia(SyntaxTrivia trivia, int initialColumn) :
                base(trivia.GetStructure())
            {
                Contract.ThrowIfFalse(trivia.HasStructure);

                _trivia = trivia;

                var root = trivia.GetStructure();
                var text = GetText();

                _initialColumn = initialColumn;
                _treeData      = (text == null) ? (TreeData) new Node(root) : new NodeAndText(root, text);
            }
        protected AbstractTriviaDataFactory(TreeData treeInfo, OptionSet optionSet)
        {
            Contract.ThrowIfNull(treeInfo);
            Contract.ThrowIfNull(optionSet);

            this.TreeInfo  = treeInfo;
            this.OptionSet = optionSet;

            for (int i = 0; i < SpaceCacheSize; i++)
            {
                _spaces[i] = new Whitespace(this.OptionSet, space: i, elastic: false, language: treeInfo.Root.Language);
            }
        }
Exemple #4
0
 public AbstractFormatEngine(
     TreeData treeData,
     OptionSet optionSet,
     IEnumerable <IFormattingRule> formattingRules,
     SyntaxToken token1,
     SyntaxToken token2)
     : this(
         treeData,
         optionSet,
         new ChainedFormattingRules(formattingRules, optionSet),
         token1,
         token2)
 {
 }
Exemple #5
0
            public AbstractComplexTrivia(OptionSet optionSet, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) :
                base(optionSet, token1.Language)
            {
                Contract.ThrowIfNull(treeInfo);

                _token1 = token1;
                _token2 = token2;

                _treatAsElastic = CommonFormattingHelpers.HasAnyWhitespaceElasticTrivia(token1, token2);

                this.TreeInfo       = treeInfo;
                this.OriginalString = this.TreeInfo.GetTextBetween(token1, token2);
                ExtractLineAndSpace(this.OriginalString, out var lineBreaks, out var spaces);

                this.LineBreaks = lineBreaks;
                this.Spaces     = spaces;
            }
        public static void ProcessTextBetweenTokens(
            this string text,
            TreeData treeInfo,
            SyntaxToken baseToken,
            int tabSize,
            out int lineBreaks,
            out int spaceOrIndentation)
        {
            // initialize out param
            lineBreaks = text.GetNumberOfLineBreaks();

            // multiple line case
            if (lineBreaks > 0)
            {
                var indentationString = text.GetLastLineText();
                spaceOrIndentation = indentationString.GetColumnFromLineOffset(indentationString.Length, tabSize);
                return;
            }

            // with tab, more expensive way. get column of token1 and then calculate right space amount
            var initialColumn = baseToken.RawKind == 0 ? 0 /* the very beginning of the file */ : treeInfo.GetOriginalColumn(tabSize, baseToken);

            spaceOrIndentation = text.ConvertTabToSpace(tabSize, baseToken.ToString().GetTextColumn(tabSize, initialColumn), text.Length);
        }
Exemple #7
0
 public Debug(SyntaxNode root, SourceText text) :
     base(root, text)
 {
     _debugNodeData = new Node(root);
 }