158 references to DirectiveTriviaSyntax
Microsoft.AspNetCore.App.Analyzers (1)
Infrastructure\VirtualChars\CSharpVirtualCharService.cs (1)
118if (node is DirectiveTriviaSyntax)
Microsoft.CodeAnalysis.CSharp (53)
Compilation\CSharpCompilation.cs (1)
3786foreach (var directive in checksumDirectives)
CSharpExtensions.cs (6)
372internal static IList<DirectiveTriviaSyntax> GetDirectives(this SyntaxNode node, Func<DirectiveTriviaSyntax, bool>? filter = null) 380public static DirectiveTriviaSyntax? GetFirstDirective(this SyntaxNode node, Func<DirectiveTriviaSyntax, bool>? predicate = null) 388public static DirectiveTriviaSyntax? GetLastDirective(this SyntaxNode node, Func<DirectiveTriviaSyntax, bool>? predicate = null)
Syntax\CSharpLineDirectiveMap.cs (3)
14internal class CSharpLineDirectiveMap : LineDirectiveMap<DirectiveTriviaSyntax> 22protected override bool ShouldAddDirective(DirectiveTriviaSyntax directive) 28protected override LineMappingEntry GetEntry(DirectiveTriviaSyntax directiveNode, SourceText sourceText, LineMappingEntry previous)
Syntax\CSharpPragmaWarningStateMap.cs (4)
47var directives = ArrayBuilder<DirectiveTriviaSyntax>.GetInstance(); 58private static void GetAllPragmaWarningDirectives(SyntaxTree syntaxTree, ArrayBuilder<DirectiveTriviaSyntax> directiveList) 60foreach (var d in syntaxTree.GetRoot().GetDirectives()) 80private static WarningStateMapEntry[] CreatePragmaWarningStateEntries(ArrayBuilder<DirectiveTriviaSyntax> directiveList)
Syntax\CSharpSyntaxNode.cs (13)
222internal IList<DirectiveTriviaSyntax> GetDirectives(Func<DirectiveTriviaSyntax, bool>? filter = null) 224return ((SyntaxNodeOrToken)this).GetDirectives<DirectiveTriviaSyntax>(filter); 230public DirectiveTriviaSyntax? GetFirstDirective(Func<DirectiveTriviaSyntax, bool>? predicate = null) 238var d = node.GetFirstDirective(predicate); 253var d = (DirectiveTriviaSyntax)tr.GetStructure()!; 270public DirectiveTriviaSyntax? GetLastDirective(Func<DirectiveTriviaSyntax, bool>? predicate = null) 278var d = node.GetLastDirective(predicate); 293var d = (DirectiveTriviaSyntax)tr.GetStructure()!;
Syntax\CSharpSyntaxTree.cs (1)
236foreach (DirectiveTriviaSyntax directive in this.GetRoot().GetDirectives(d =>
Syntax\DirectiveTriviaSyntax.cs (21)
67public DirectiveTriviaSyntax? GetNextDirective(Func<DirectiveTriviaSyntax, bool>? predicate = null) 77var d = (DirectiveTriviaSyntax)tr.GetStructure()!; 98public DirectiveTriviaSyntax? GetPreviousDirective(Func<DirectiveTriviaSyntax, bool>? predicate = null) 108var d = (DirectiveTriviaSyntax)tr.GetStructure()!; 129public List<DirectiveTriviaSyntax> GetRelatedDirectives() 131var list = new List<DirectiveTriviaSyntax>(); 136private void GetRelatedDirectives(List<DirectiveTriviaSyntax> list) 139var p = this.GetPreviousRelatedDirective(); 148var n = this.GetNextRelatedDirective(); 156private DirectiveTriviaSyntax? GetNextRelatedDirective() 158DirectiveTriviaSyntax? d = this; 222private DirectiveTriviaSyntax? GetNextPossiblyRelatedDirective() 224DirectiveTriviaSyntax? d = this; 256private DirectiveTriviaSyntax? GetPreviousRelatedDirective() 258DirectiveTriviaSyntax? d = this; 323private DirectiveTriviaSyntax? GetPreviousPossiblyRelatedDirective() 325DirectiveTriviaSyntax? d = this;
Syntax\NullableContextStateMap.cs (1)
141foreach (var d in tree.GetRoot().GetDirectives())
Syntax\SyntaxNodeRemover.cs (3)
145if (trivia.IsDirective && trivia.GetStructure() is DirectiveTriviaSyntax directive) 436.Select(tr => (DirectiveTriviaSyntax)tr.GetStructure()!); 474private static bool HasRelatedDirectives(DirectiveTriviaSyntax directive)
Microsoft.CodeAnalysis.CSharp.CodeStyle (25)
src\Analyzers\CSharp\Analyzers\RemoveUnnecessaryNullableDirective\CSharpRemoveUnnecessaryNullableDirectiveDiagnosticAnalyzer.cs (2)
113for (var directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective()) 196for (var directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective())
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (1)
118if (node is DirectiveTriviaSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\BlockSyntaxExtensions.cs (4)
68var firstDirective = (DirectiveTriviaSyntax)leadingDirectives.First().GetStructure()!; 83foreach (var conditionalDirective in conditionalDirectives) 105if (!conditionalDirectives.Contains((DirectiveTriviaSyntax)closeBraceDirective.GetStructure()!))
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
23var directive = token.GetAncestor<DirectiveTriviaSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\DirectiveSyntaxExtensions.cs (10)
17private static readonly ConditionalWeakTable<SyntaxNode, DirectiveInfo<DirectiveTriviaSyntax>> s_rootToDirectiveInfo = new(); 29private static DirectiveInfo<DirectiveTriviaSyntax> GetDirectiveInfo(SyntaxNode node, CancellationToken cancellationToken) 34private static DirectiveInfo<DirectiveTriviaSyntax> GetDirectiveInfoForRoot(SyntaxNode root, CancellationToken cancellationToken) 35=> CodeAnalysis.Shared.Extensions.SyntaxNodeExtensions.GetDirectiveInfoForRoot<DirectiveTriviaSyntax>( 38internal static DirectiveTriviaSyntax? GetMatchingDirective(this DirectiveTriviaSyntax directive, CancellationToken cancellationToken) 51public static ImmutableArray<DirectiveTriviaSyntax> GetMatchingConditionalDirectives(this DirectiveTriviaSyntax directive, CancellationToken cancellationToken) 63private static bool IsRegionDirective(DirectiveTriviaSyntax directive) 66private static bool IsConditionalDirective(DirectiveTriviaSyntax directive)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ParenthesizedExpressionSyntaxExtensions.cs (1)
261if (nodeParent is DirectiveTriviaSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (3)
556var match = ((DirectiveTriviaSyntax)structure).GetMatchingDirective(cancellationToken); 570var directives = ((DirectiveTriviaSyntax)structure).GetMatchingConditionalDirectives(cancellationToken);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (2)
329var endDirective = pragmaWarningDirectiveTrivia.GetNextDirective(trivia => IsFormatDirective(trivia, SyntaxKind.RestoreKeyword)); 340private static bool IsFormatDirective(DirectiveTriviaSyntax? trivia, SyntaxKind disableOrRestoreKeyword)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs (1)
131=> node is DirectiveTriviaSyntax;
Microsoft.CodeAnalysis.CSharp.Features (22)
BraceMatching\CSharpDirectiveTriviaBraceMatcher.cs (6)
18internal class CSharpDirectiveTriviaBraceMatcher : AbstractDirectiveTriviaBraceMatcher<DirectiveTriviaSyntax, 29protected override ImmutableArray<DirectiveTriviaSyntax> GetMatchingConditionalDirectives(DirectiveTriviaSyntax directive, CancellationToken cancellationToken) 32protected override DirectiveTriviaSyntax? GetMatchingDirective(DirectiveTriviaSyntax directive, CancellationToken cancellationToken) 35internal override TextSpan GetSpanForTagging(DirectiveTriviaSyntax directive)
CodeRefactorings\EnableNullable\EnableNullableCodeRefactoringProvider.cs (4)
26private static readonly Func<DirectiveTriviaSyntax, bool> s_isNullableDirectiveTriviaPredicate = 120var firstDirective = root.GetFirstDirective(s_isNullableDirectiveTriviaPredicate); 129for (var directive = firstDirective; directive is not null; directive = directive.GetNextDirective(s_isNullableDirectiveTriviaPredicate)) 243var firstRelevantDirective = root.GetFirstDirective(static directive => directive.Kind() is SyntaxKind.NullableDirectiveTrivia or SyntaxKind.IfDirectiveTrivia);
Completion\CompletionProviders\SnippetCompletionProvider.cs (1)
126var directive = leftToken.GetAncestor<DirectiveTriviaSyntax>();
ConvertToRawString\ConvertToRawStringHelpers.cs (1)
69if (node is DirectiveTriviaSyntax)
Highlighting\KeywordHighlighters\ConditionalPreprocessorHighlighter.cs (2)
20internal sealed class ConditionalPreprocessorHighlighter() : AbstractKeywordHighlighter<DirectiveTriviaSyntax> 23DirectiveTriviaSyntax directive, List<TextSpan> highlights, CancellationToken cancellationToken)
Highlighting\KeywordHighlighters\RegionHighlighter.cs (2)
20internal class RegionHighlighter : AbstractKeywordHighlighter<DirectiveTriviaSyntax> 29DirectiveTriviaSyntax directive, List<TextSpan> highlights, CancellationToken cancellationToken)
QuickInfo\CSharpSyntacticQuickInfoProvider.cs (1)
140if (token.Parent is DirectiveTriviaSyntax directiveTrivia)
src\Analyzers\CSharp\Analyzers\RemoveUnnecessaryNullableDirective\CSharpRemoveUnnecessaryNullableDirectiveDiagnosticAnalyzer.cs (2)
113for (var directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective()) 196for (var directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective())
Structure\Providers\IfDirectiveTriviaStructureProvider.cs (2)
31var directive = allRelatedDirectives[i]; 39var nextDirective = allRelatedDirectives[i + 1];
Structure\Providers\RegionDirectiveStructureProvider.cs (1)
16private static string GetBannerText(DirectiveTriviaSyntax simpleDirective)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (30)
Diagnostics\LineSpanDirectiveTests.cs (2)
463var directives = tree.GetRoot().DescendantNodesAndSelf(descendIntoTrivia: true).OfType<DirectiveTriviaSyntax>(); 464foreach (var directive in directives)
LexicalAndXml\PreprocessorTests.cs (5)
130foreach (var dt in directives) 149foreach (var dt in directives) 160var dt = directives[idx++]; 297var dt = directives[0]; 301private void VerifyDirectivePragma(DirectiveTriviaSyntax dt, PragmaInfo expected)
Parsing\ScriptParsingTests.cs (1)
9731private void TestShebang(DirectiveTriviaSyntax directive, string expectedSkippedText)
Syntax\SyntaxNodeTests.cs (22)
337var descendantDirectives = expr.DescendantNodesAndSelf(n => n.ContainsDirectives, descendIntoTrivia: true).OfType<DirectiveTriviaSyntax>().ToList(); 1378var d = tree.GetCompilationUnitRoot().GetFirstDirective(); 1390var d = tree.GetCompilationUnitRoot().GetLastDirective(); 1407var d1 = tree.GetCompilationUnitRoot().GetFirstDirective(); 1410var d2 = d1.GetNextDirective(); 1413var d3 = d2.GetNextDirective(); 1416var d4 = d3.GetNextDirective(); 1419var d5 = d4.GetNextDirective(); 1435var d1 = tree.GetCompilationUnitRoot().GetLastDirective(); 1438var d2 = d1.GetPreviousDirective(); 1441var d3 = d2.GetPreviousDirective(); 1444var d4 = d3.GetPreviousDirective(); 1447var d5 = d4.GetPreviousDirective(); 1494var d = tree.GetCompilationUnitRoot().GetFirstDirective(); 1525var d = tree.GetCompilationUnitRoot().GetFirstDirective(); 1564var d = tree.GetCompilationUnitRoot().GetLastDirective(); 1595var d = tree.GetCompilationUnitRoot().GetFirstDirective(); 1629var d = tree.GetCompilationUnitRoot().GetFirstDirective(); 1663var d = tree.GetCompilationUnitRoot().GetLastDirective(); 1693var d = tree.GetCompilationUnitRoot().GetLastDirective(); 1716var d = tree.GetCompilationUnitRoot().GetFirstDirective(); 1737var d = tree.GetCompilationUnitRoot().GetLastDirective();
Microsoft.CodeAnalysis.CSharp.Workspaces (26)
Classification\Worker.cs (1)
254ClassifyPreprocessorDirective((DirectiveTriviaSyntax)trivia.GetStructure()!);
Classification\Worker_Preprocesser.cs (2)
12private void ClassifyPreprocessorDirective(DirectiveTriviaSyntax node) 78private void ClassifyDirectiveTrivia(DirectiveTriviaSyntax node, bool allowComments = true)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (1)
118if (node is DirectiveTriviaSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\BlockSyntaxExtensions.cs (4)
68var firstDirective = (DirectiveTriviaSyntax)leadingDirectives.First().GetStructure()!; 83foreach (var conditionalDirective in conditionalDirectives) 105if (!conditionalDirectives.Contains((DirectiveTriviaSyntax)closeBraceDirective.GetStructure()!))
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
23var directive = token.GetAncestor<DirectiveTriviaSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\DirectiveSyntaxExtensions.cs (10)
17private static readonly ConditionalWeakTable<SyntaxNode, DirectiveInfo<DirectiveTriviaSyntax>> s_rootToDirectiveInfo = new(); 29private static DirectiveInfo<DirectiveTriviaSyntax> GetDirectiveInfo(SyntaxNode node, CancellationToken cancellationToken) 34private static DirectiveInfo<DirectiveTriviaSyntax> GetDirectiveInfoForRoot(SyntaxNode root, CancellationToken cancellationToken) 35=> CodeAnalysis.Shared.Extensions.SyntaxNodeExtensions.GetDirectiveInfoForRoot<DirectiveTriviaSyntax>( 38internal static DirectiveTriviaSyntax? GetMatchingDirective(this DirectiveTriviaSyntax directive, CancellationToken cancellationToken) 51public static ImmutableArray<DirectiveTriviaSyntax> GetMatchingConditionalDirectives(this DirectiveTriviaSyntax directive, CancellationToken cancellationToken) 63private static bool IsRegionDirective(DirectiveTriviaSyntax directive) 66private static bool IsConditionalDirective(DirectiveTriviaSyntax directive)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ParenthesizedExpressionSyntaxExtensions.cs (1)
261if (nodeParent is DirectiveTriviaSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (3)
556var match = ((DirectiveTriviaSyntax)structure).GetMatchingDirective(cancellationToken); 570var directives = ((DirectiveTriviaSyntax)structure).GetMatchingConditionalDirectives(cancellationToken);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (2)
329var endDirective = pragmaWarningDirectiveTrivia.GetNextDirective(trivia => IsFormatDirective(trivia, SyntaxKind.RestoreKeyword)); 340private static bool IsFormatDirective(DirectiveTriviaSyntax? trivia, SyntaxKind disableOrRestoreKeyword)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs (1)
131=> node is DirectiveTriviaSyntax;
Microsoft.VisualStudio.LanguageServices.CSharp (1)
LanguageService\CSharpHelpContextService.cs (1)
345var directive = token.GetAncestor<DirectiveTriviaSyntax>();