private bool ApplyDynamicSpacesOperation(AdjustSpacesOperation operation, int pairIndex) { var triviaInfo = _tokenStream.GetTriviaData(pairIndex); if (triviaInfo.SecondTokenIsFirstTokenOnLine) { return(false); } Contract.ThrowIfFalse(triviaInfo.LineBreaks == 0); var indentation = _context.GetBaseIndentation(_tokenStream.GetToken(pairIndex + 1)); var previousToken = _tokenStream.GetToken(pairIndex); bool multipleLines; int tokenLength; _tokenStream.GetTokenLength(previousToken, out tokenLength, out multipleLines); // get end column of previous token var endColumnOfPreviousToken = multipleLines ? tokenLength : _tokenStream.GetCurrentColumn(previousToken) + tokenLength; // check whether current position is less than indentation if (endColumnOfPreviousToken < indentation) { _tokenStream.ApplyChange(pairIndex, triviaInfo.WithSpace(indentation - endColumnOfPreviousToken, _context, _formattingRules)); return(true); } // delegate to normal single-line space applier return(ApplySpaceIfSingleLine(operation, pairIndex)); }
private void ApplyTriviaOperations(FormattingContext context, TokenStream tokenStream, CancellationToken cancellationToken) { // trivia formatting result appliers Action <int, TriviaData> regularApplier = (tokenPairIndex, info) => { tokenStream.ApplyChange(tokenPairIndex, info); }; // trivia formatting applier Action <int> triviaFormatter = tokenPairIndex => { var triviaInfo = tokenStream.GetTriviaData(tokenPairIndex); triviaInfo.Format(context, this.formattingRules, regularApplier, cancellationToken, tokenPairIndex); }; this.TaskExecutor.For(0, tokenStream.TokenCount - 1, triviaFormatter, cancellationToken); }
private void ApplyTriviaOperations(FormattingContext context, TokenStream tokenStream, CancellationToken cancellationToken) { // trivia formatting result appliers void regularApplier(int tokenPairIndex, TriviaData info) { tokenStream.ApplyChange(tokenPairIndex, info); } // trivia formatting applier void triviaFormatter(int tokenPairIndex) { var triviaInfo = tokenStream.GetTriviaData(tokenPairIndex); triviaInfo.Format(context, _formattingRules, regularApplier, cancellationToken, tokenPairIndex); } this.TaskExecutor.For(0, tokenStream.TokenCount - 1, triviaFormatter, cancellationToken); }
private void ApplyTriviaOperations(FormattingContext context, TokenStream tokenStream, CancellationToken cancellationToken) { // trivia formatting result appliers void regularApplier(int tokenPairIndex, TriviaData info) { tokenStream.ApplyChange(tokenPairIndex, info); } // trivia formatting applier void triviaFormatter(int tokenPairIndex) { var triviaInfo = tokenStream.GetTriviaData(tokenPairIndex); triviaInfo.Format(context, _formattingRules, regularApplier, cancellationToken, tokenPairIndex); } for (var i = 0; i < tokenStream.TokenCount - 1; i++) { cancellationToken.ThrowIfCancellationRequested(); triviaFormatter(i); } }