Example #1
0
        public void AddInitialSuppressOperation(SuppressOperation operation)
        {
            // don't add stuff if it is empty
            if (operation == null || operation.TextSpan.IsEmpty)
            {
                return;
            }

            var onSameLine = _tokenStream.TwoTokensOriginallyOnSameLine(operation.StartToken, operation.EndToken);

            AddSuppressOperation(operation, onSameLine);
        }
Example #2
0
        public void AddSuppressOperations(
            List <SuppressOperation> operations,
            CancellationToken cancellationToken)
        {
            var valuePairs = new ValueTuple <SuppressOperation, bool, bool> [operations.Count];

            // TODO: think about a way to figure out whether it is already suppressed and skip the expensive check below.
            this.engine.TaskExecutor.For(0, operations.Count, i =>
            {
                var operation = operations[i];

                // if an operation contains elastic trivia itself and the operation is not marked to ignore the elastic triva
                // ignore the operation
                if (operation.ContainsElasticTrivia(tokenStream) && !operation.Option.IsOn(SuppressOption.IgnoreElastic))
                {
                    // don't bother to calculate line alignment between tokens
                    valuePairs[i] = ValueTuple.Create(operation, false, false);
                    return;
                }

                var onSameLine = tokenStream.TwoTokensOriginallyOnSameLine(operation.StartToken, operation.EndToken);
                valuePairs[i]  = ValueTuple.Create(operation, true, onSameLine);
            }, cancellationToken);

            valuePairs.Do(v =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (v.Item2)
                {
                    AddSuppressOperation(v.Item1, v.Item3);
                }
            });
        }
            public bool Apply(AdjustNewLinesOperation operation, int pairIndex, CancellationToken cancellationToken)
            {
                if (operation.Option == AdjustNewLinesOption.PreserveLines)
                {
                    return(ApplyPreserveLinesOperation(operation, pairIndex, cancellationToken));
                }
                else if (operation.Option == AdjustNewLinesOption.ForceLines)
                {
                    return(ApplyForceLinesOperation(operation, pairIndex, cancellationToken));
                }
                else
                {
                    Debug.Assert(operation.Option == AdjustNewLinesOption.ForceIfSameLine);

                    // We force the tokens to the different line only they are on the same line
                    // else we leave the tokens as it is (Note: We should not preserve too. If we
                    // we do, then that will be counted as a line operation and the indentation of
                    // the second token will be modified)
                    if (tokenStream.TwoTokensOriginallyOnSameLine(tokenStream.GetToken(pairIndex),
                                                                  tokenStream.GetToken(pairIndex + 1)))
                    {
                        return(ApplyForceLinesOperation(operation, pairIndex, cancellationToken));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }