예제 #1
0
 public AbstractFormatEngine(
     TreeData treeData,
     OptionSet optionSet,
     IEnumerable <IFormattingRule> formattingRules,
     SyntaxToken token1,
     SyntaxToken token2,
     TaskExecutor executor)
     : this(
         treeData,
         optionSet,
         new ChainedFormattingRules(formattingRules, optionSet),
         token1,
         token2,
         executor)
 {
 }
예제 #2
0
        internal AbstractFormatEngine(
            TreeData treeData,
            OptionSet optionSet,
            ChainedFormattingRules formattingRules,
            SyntaxToken token1,
            SyntaxToken token2,
            TaskExecutor executor)
        {
            Contract.ThrowIfNull(optionSet);
            Contract.ThrowIfNull(treeData);
            Contract.ThrowIfNull(formattingRules);
            Contract.ThrowIfNull(executor);

            Contract.ThrowIfTrue(treeData.Root.IsInvalidTokenRange(token1, token2));

            this.OptionSet   = optionSet;
            this.TreeData    = treeData;
            _formattingRules = formattingRules;

            _token1 = token1;
            _token2 = token2;

            // get span and common root
            this.SpanToFormat = GetSpanToFormat();
            _commonRoot       = token1.GetCommonRoot(token2);
            if (token1 == default)
            {
                _language = token2.Language;
            }
            else
            {
                _language = token1.Language;
            }

            // set synchronous task executor if it is enabled (explicitly or as part of debug mode) or if there is not
            // many things to format
            var synchronousExecutorAllowed =
                !optionSet.GetOption(FormattingOptions.AllowConcurrent) ||
                optionSet.GetOption(FormattingOptions.DebugMode, _language);
            var useSynchronousExecutor = synchronousExecutorAllowed || SpanToFormat.Length < ConcurrentThreshold;

            TaskExecutor = useSynchronousExecutor ? TaskExecutor.Synchronous : executor;
        }
예제 #3
0
        internal AbstractFormatEngine(
            TreeData treeData,
            OptionSet optionSet,
            ChainedFormattingRules formattingRules,
            SyntaxToken token1,
            SyntaxToken token2,
            TaskExecutor executor)
        {
            Contract.ThrowIfNull(optionSet);
            Contract.ThrowIfNull(treeData);
            Contract.ThrowIfNull(formattingRules);
            Contract.ThrowIfNull(executor);

            Contract.ThrowIfTrue(treeData.Root.IsInvalidTokenRange(token1, token2));

            this.OptionSet       = optionSet;
            this.TreeData        = treeData;
            this.formattingRules = formattingRules;

            this.token1 = token1;
            this.token2 = token2;

            // get span and common root
            this.SpanToFormat = GetSpanToFormat();
            this.commonRoot   = token1.GetCommonRoot(token2);
            if (token1 == default(SyntaxToken))
            {
                this.language = token2.Language;
            }
            else
            {
                this.language = token1.Language;
            }

            // set synchronous task executor if it is debug mode or if there is not many things to format
            this.TaskExecutor = optionSet.GetOption(FormattingOptions.DebugMode, this.language) ? TaskExecutor.Synchronous :
                                (SpanToFormat.Length < ConcurrentThreshold) ? TaskExecutor.Synchronous : executor;
        }