Extensions\RazorSyntaxNodeExtensions.cs (38)
18private static bool IsDirective(SyntaxNode node, DirectiveDescriptor directive, [NotNullWhen(true)] out RazorDirectiveBodySyntax? body)
34internal static bool IsSectionDirective(this SyntaxNode node)
37internal static bool IsCodeBlockDirective(this SyntaxNode node)
40internal static bool IsUsingDirective(this SyntaxNode node, out SyntaxTokenList tokens)
58internal static bool IsConstrainedTypeParamDirective(this SyntaxNode node, [NotNullWhen(true)] out CSharpStatementLiteralSyntax? typeParamNode, [NotNullWhen(true)] out CSharpStatementLiteralSyntax? conditionsNode)
77internal static bool IsAttributeDirective(this SyntaxNode node, [NotNullWhen(true)] out CSharpStatementLiteralSyntax? attributeNode)
90internal static bool IsCodeDirective(this SyntaxNode node)
102internal static bool IsFunctionsDirective(this SyntaxNode node)
117internal static SyntaxNode? GetOutermostNode(this SyntaxNode owner)
119var node = owner.Parent;
125var lastNode = node;
145var parent = node.Parent;
151foreach (var child in parent.ChildNodes())
188public static bool ContainsOnlyWhitespace(this SyntaxNode node, bool includingNewLines = true)
202public static LinePositionSpan GetLinePositionSpan(this SyntaxNode node, RazorSourceDocument sourceDocument)
229public static SyntaxNode? FindInnermostNode(this SyntaxNode node, int index, bool includeWhitespace = false, bool walkMarkersBack = true)
265public static SyntaxNode? FindNode(this SyntaxNode @this, TextSpan span, bool includeWhitespace = false, bool getInnermostNodeForTie = false)
269return ThrowHelper.ThrowArgumentOutOfRangeException<SyntaxNode?>(nameof(span));
272var node = @this.FindToken(span.Start, includeWhitespace)
274.FirstAncestorOrSelf<SyntaxNode>(a => a.Span.Contains(span));
291var parent = node.Parent;
311public static bool ExistsOnTarget(this SyntaxNode node, SyntaxNode target)
316var matchingNode = target.DescendantNodesAndSelf()
324public static SyntaxNode RemoveEmptyNewLines(this SyntaxNode node)
345public static bool IsCSharpNode(this SyntaxNode node, [NotNullWhen(true)] out CSharpCodeBlockSyntax? csharpCodeBlock)
353var innerCSharpNode = outerCSharpCodeBlock.ChildNodes().FirstOrDefault(
423public static bool IsAnyAttributeSyntax(this SyntaxNode node)
435public static bool TryGetLinePositionSpanWithoutWhitespace(this SyntaxNode node, RazorSourceDocument source, out LinePositionSpan linePositionSpan)
479public static bool TryGetFirstToken(this SyntaxNode node, out SyntaxToken result)
482public static bool TryGetFirstToken(this SyntaxNode node, bool includeZeroWidth, out SyntaxToken result)
488public static bool TryGetLastToken(this SyntaxNode node, out SyntaxToken result)
491public static bool TryGetLastToken(this SyntaxNode node, bool includeZeroWidth, out SyntaxToken result)
497public static TextSpan SpanWithoutTrailingNewLines(this SyntaxNode node, SourceText sourceText)
Formatting\Passes\CSharpOnTypeFormattingPass.cs (12)
28using RazorSyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode;
337out var owner))
491if (!ShouldFormat(context, endSpan, allowImplicitStatements: false, out var owner))
545private static bool IsOnSingleLine(RazorSyntaxNode node, SourceText text)
592if (!ShouldFormat(context, mappingSpan, options, out var owner))
624if (!ShouldFormat(context, lineStartSpan, allowImplicitStatements: true, out var owner))
688var root = context.CodeDocument.GetRequiredSyntaxRoot();
703var scopeOwner = root.FindInnermostNode(originalLocation);
854private static bool ShouldFormat(FormattingContext context, TextSpan mappingSpan, bool allowImplicitStatements, out RazorSyntaxNode? foundOwner)
860private static bool ShouldFormat(FormattingContext context, TextSpan mappingSpan, ShouldFormatOptions options, out RazorSyntaxNode? foundOwner)
871var root = context.CodeDocument.GetRequiredSyntaxRoot();
872var owner = root.FindInnermostNode(mappingSpan.Start, includeWhitespace: true);
Formatting\Passes\RazorFormattingPass.cs (23)
19using RazorSyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode;
20using RazorSyntaxNodeList = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxList<Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode>;
60foreach (var node in syntaxTree.Root.DescendantNodes())
72private static void TryFormatBlocks(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
82private static bool TryFormatSectionBlock(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
137private static bool TryFormatFunctionsBlock(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
178private static bool TryFormatCSharpExplicitTransition(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
200private static bool TryFormatComplexCSharpBlock(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
213var openBraceNode = outerCodeBlock.Children.PreviousSiblingOrSelf(innerCodeBlock);
214var closeBraceNode = outerCodeBlock.Children.NextSiblingOrSelf(innerCodeBlock);
222private static bool TryFormatHtmlInCSharp(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
231var openBraceNode = csharpCodeBlock.Children.PreviousSiblingOrSelf(markupBlockNode);
232var closeBraceNode = csharpCodeBlock.Children.NextSiblingOrSelf(markupBlockNode);
240private static void TryFormatCSharpBlockStructure(FormattingContext context, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, RazorSyntaxNode node)
298private static void TryFormatSingleLineDirective(ref PooledArrayBuilder<TextChange> changes, RazorSyntaxNode node)
314foreach (var child in children)
333static bool IsSingleLineDirective(RazorSyntaxNode node, out RazorSyntaxNodeList children)
349private static void FormatWhitespaceBetweenDirectiveAndBrace(RazorSyntaxNode node, RazorDirectiveSyntax directive, ref PooledArrayBuilder<TextChange> changes, RazorSourceDocument source, FormattingContext context, bool forceNewLine)
374private static bool FormatBlock(FormattingContext context, RazorSourceDocument source, RazorSyntaxNode? directiveNode, RazorSyntaxNode openBraceNode, RazorSyntaxNode codeNode, RazorSyntaxNode closeBraceNode, ref PooledArrayBuilder<TextChange> changes)
475private static bool IsCodeOrFunctionsBlock(RazorSyntaxNode keyword)