public BottomUpBaseIndentationFinder( ChainedFormattingRules formattingRules, int tabSize, int indentationSize, TokenStream?tokenStream, IHeaderFacts headerFacts) { Contract.ThrowIfNull(formattingRules); _formattingRules = formattingRules; _tabSize = tabSize; _indentationSize = indentationSize; _tokenStream = tokenStream; _headerFacts = headerFacts; }
internal static int GetAdjustedIndentationDelta( this IndentBlockOperation operation, IHeaderFacts headerFacts, SyntaxNode root, SyntaxToken indentationAnchor) { if (operation.Option.IsOn(IndentBlockOption.AbsolutePosition)) { // Absolute positioning is absolute return(operation.IndentationDeltaOrPosition); } if (!operation.Option.IsOn(IndentBlockOption.IndentIfConditionOfAnchorToken)) { // No adjustment operations are being applied return(operation.IndentationDeltaOrPosition); } // Consider syntax forms similar to the following: // // if (conditionLine1 // conditionLine2) // // Adjustments may be requested for conditionLine2 in cases where the anchor for relative indentation is the // first token of the containing statement (in this case, the 'if' token). if (headerFacts.IsOnIfStatementHeader(root, operation.BaseToken.SpanStart, out var conditionStatement) || headerFacts.IsOnWhileStatementHeader(root, operation.BaseToken.SpanStart, out conditionStatement)) { if (conditionStatement.GetFirstToken() == indentationAnchor) { // The node is located within the condition of a conditional block statement (or // syntactically-similar), uses a relative anchor to the block statement, and has requested an // additional indentation adjustment for this case. return(operation.IndentationDeltaOrPosition + 1); } } // No adjustments were necessary/applicable return(operation.IndentationDeltaOrPosition); }
/// <summary> /// Checks if the position is on the header of a type (from the start of the type up through it's name). /// </summary> public static bool IsOnTypeHeader(this IHeaderFacts headerFacts, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode?typeDeclaration) => headerFacts.IsOnTypeHeader(root, position, fullHeader: false, out typeDeclaration);