示例#1
0
            private IList <TokenData> GetTokenWithIndices(IEnumerable <SyntaxToken> tokens)
            {
                var list = new List <TokenData>();

                foreach (var token in tokens)
                {
                    // if the token is invisible or not exist, skip it.
                    if (token.RawKind == 0 || token.Width() <= 0)
                    {
                        continue;
                    }

                    var tokenWithIndex = _tokenStream.GetTokenData(token);
                    if (tokenWithIndex.IndexInStream < 0)
                    {
                        // this token is not inside of the formatting span, ignore
                        continue;
                    }

                    list.Add(tokenWithIndex);
                }

                list.Sort((t1, t2) => t1.IndexInStream - t2.IndexInStream);
                return(list);
            }
示例#2
0
        public static bool ContainsElasticTrivia(this SuppressOperation operation, TokenStream tokenStream)
        {
            var startToken    = tokenStream.GetTokenData(operation.StartToken);
            var nextToken     = startToken.GetNextTokenData();
            var endToken      = tokenStream.GetTokenData(operation.EndToken);
            var previousToken = endToken.GetPreviousTokenData();

            return(tokenStream.GetTriviaData(startToken, nextToken).TreatAsElastic || tokenStream.GetTriviaData(previousToken, endToken).TreatAsElastic);
        }
示例#3
0
            public List <IEnumerable <TokenPairWithOperations> > GetPartitions(int partitionCount, CancellationToken cancellationToken)
            {
                using (Logger.LogBlock(FunctionId.Formatting_Partitions, cancellationToken))
                {
                    Contract.ThrowIfFalse(partitionCount > 0);

                    var list = new List <IEnumerable <TokenPairWithOperations> >();

                    // too small items in the list. give out one list
                    int perPartition = _operationPairs.Length / partitionCount;
                    if (perPartition < 10 || partitionCount <= 1 || _operationPairs.Length < MinimumItemsPerPartition)
                    {
                        list.Add(GetOperationPairsFromTo(0, _operationPairs.Length));
                        return(list);
                    }

                    // split items up to the partition count with about same number of items if possible
                    // this algorithm has one problem. if there is an operation that marked whole tree
                    // as inseparable region, then it wouldn't go into the inseparable regions to find
                    // local parts that could run concurrently; which means everything will run
                    // synchronously.
                    var currentOperationIndex = 0;
                    while (currentOperationIndex < _operationPairs.Length)
                    {
                        int nextPartitionStartOperationIndex;
                        if (!TryGetNextPartitionIndex(currentOperationIndex, perPartition, out nextPartitionStartOperationIndex))
                        {
                            // reached end of operation pairs
                            list.Add(GetOperationPairsFromTo(currentOperationIndex, _operationPairs.Length));
                            break;
                        }

                        var nextToken = GetNextPartitionToken(nextPartitionStartOperationIndex, perPartition, cancellationToken);
                        if (nextToken.RawKind == 0)
                        {
                            // reached the last token in the tree
                            list.Add(GetOperationPairsFromTo(currentOperationIndex, _operationPairs.Length));
                            break;
                        }

                        var nextTokenWithIndex = _tokenStream.GetTokenData(nextToken);
                        if (nextTokenWithIndex.IndexInStream < 0)
                        {
                            // first token for next partition is out side of valid token stream
                            list.Add(GetOperationPairsFromTo(currentOperationIndex, _operationPairs.Length));
                            break;
                        }

                        Contract.ThrowIfFalse(currentOperationIndex < nextTokenWithIndex.IndexInStream);
                        Contract.ThrowIfFalse(nextTokenWithIndex.IndexInStream <= _operationPairs.Length);

                        list.Add(GetOperationPairsFromTo(currentOperationIndex, nextTokenWithIndex.IndexInStream));
                        currentOperationIndex = nextTokenWithIndex.IndexInStream;
                    }

                    return(list);
                }
            }