Skip to content

Commit 6a18333

Browse files
authored
Update ignored directives public API (dotnet#77968)
* Remove experiment * Add Content token to IgnoredDirectiveTriviaSyntax * Add Content token to ShebangDirectiveTriviaSyntax * Fixup public API * Fixup semantic search API list * Fix CLI flag in error message * Remove Update API * Update SemanticSearch API list
1 parent e6d795f commit 6a18333

31 files changed

+269
-132
lines changed

eng/targets/Settings.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
<!-- TODO: https://github.com/dotnet/roslyn/issues/71667 -->
1818
<NoWarn>$(NoWarn);NU1507</NoWarn>
1919

20-
<NoWarn>$(NoWarn);RSEXPERIMENTAL005</NoWarn>
21-
2220
<CommonExtensionInstallationRoot>CommonExtensions</CommonExtensionInstallationRoot>
2321
<LanguageServicesExtensionInstallationFolder>Microsoft\VBCSharp\LanguageServices</LanguageServicesExtensionInstallationFolder>
2422

src/Compilers/CSharp/Portable/CSharpResources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8138,7 +8138,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
81388138
<value>'#:' directives cannot be after first token in file</value>
81398139
</data>
81408140
<data name="ERR_PPIgnoredNeedsFileBasedProgram" xml:space="preserve">
8141-
<value>'#:' directives can be only used in file-based programs ('/feature:FileBasedProgram')</value>
8141+
<value>'#:' directives can be only used in file-based programs ('-features:FileBasedProgram')</value>
81428142
</data>
81438143
<data name="ERR_PPIgnoredFollowsIf" xml:space="preserve">
81448144
<value>'#:' directives cannot be after '#if' directive</value>

src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Internal.Generated.cs

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26608,51 +26608,68 @@ internal sealed partial class IgnoredDirectiveTriviaSyntax : DirectiveTriviaSynt
2660826608
{
2660926609
internal readonly SyntaxToken hashToken;
2661026610
internal readonly SyntaxToken colonToken;
26611+
internal readonly SyntaxToken? content;
2661126612
internal readonly SyntaxToken endOfDirectiveToken;
2661226613
internal readonly bool isActive;
2661326614

26614-
internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
26615+
internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken? content, SyntaxToken endOfDirectiveToken, bool isActive, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
2661526616
: base(kind, diagnostics, annotations)
2661626617
{
26617-
this.SlotCount = 3;
26618+
this.SlotCount = 4;
2661826619
this.AdjustFlagsAndWidth(hashToken);
2661926620
this.hashToken = hashToken;
2662026621
this.AdjustFlagsAndWidth(colonToken);
2662126622
this.colonToken = colonToken;
26623+
if (content != null)
26624+
{
26625+
this.AdjustFlagsAndWidth(content);
26626+
this.content = content;
26627+
}
2662226628
this.AdjustFlagsAndWidth(endOfDirectiveToken);
2662326629
this.endOfDirectiveToken = endOfDirectiveToken;
2662426630
this.isActive = isActive;
2662526631
}
2662626632

26627-
internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive, SyntaxFactoryContext context)
26633+
internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken? content, SyntaxToken endOfDirectiveToken, bool isActive, SyntaxFactoryContext context)
2662826634
: base(kind)
2662926635
{
2663026636
this.SetFactoryContext(context);
26631-
this.SlotCount = 3;
26637+
this.SlotCount = 4;
2663226638
this.AdjustFlagsAndWidth(hashToken);
2663326639
this.hashToken = hashToken;
2663426640
this.AdjustFlagsAndWidth(colonToken);
2663526641
this.colonToken = colonToken;
26642+
if (content != null)
26643+
{
26644+
this.AdjustFlagsAndWidth(content);
26645+
this.content = content;
26646+
}
2663626647
this.AdjustFlagsAndWidth(endOfDirectiveToken);
2663726648
this.endOfDirectiveToken = endOfDirectiveToken;
2663826649
this.isActive = isActive;
2663926650
}
2664026651

26641-
internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive)
26652+
internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken? content, SyntaxToken endOfDirectiveToken, bool isActive)
2664226653
: base(kind)
2664326654
{
26644-
this.SlotCount = 3;
26655+
this.SlotCount = 4;
2664526656
this.AdjustFlagsAndWidth(hashToken);
2664626657
this.hashToken = hashToken;
2664726658
this.AdjustFlagsAndWidth(colonToken);
2664826659
this.colonToken = colonToken;
26660+
if (content != null)
26661+
{
26662+
this.AdjustFlagsAndWidth(content);
26663+
this.content = content;
26664+
}
2664926665
this.AdjustFlagsAndWidth(endOfDirectiveToken);
2665026666
this.endOfDirectiveToken = endOfDirectiveToken;
2665126667
this.isActive = isActive;
2665226668
}
2665326669

2665426670
public override SyntaxToken HashToken => this.hashToken;
2665526671
public SyntaxToken ColonToken => this.colonToken;
26672+
public SyntaxToken? Content => this.content;
2665626673
public override SyntaxToken EndOfDirectiveToken => this.endOfDirectiveToken;
2665726674
public override bool IsActive => this.isActive;
2665826675

@@ -26661,7 +26678,8 @@ internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, Sy
2666126678
{
2666226679
0 => this.hashToken,
2666326680
1 => this.colonToken,
26664-
2 => this.endOfDirectiveToken,
26681+
2 => this.content,
26682+
3 => this.endOfDirectiveToken,
2666526683
_ => null,
2666626684
};
2666726685

@@ -26670,11 +26688,11 @@ internal IgnoredDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, Sy
2667026688
public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitIgnoredDirectiveTrivia(this);
2667126689
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor) => visitor.VisitIgnoredDirectiveTrivia(this);
2667226690

26673-
public IgnoredDirectiveTriviaSyntax Update(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive)
26691+
public IgnoredDirectiveTriviaSyntax Update(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken content, SyntaxToken endOfDirectiveToken, bool isActive)
2667426692
{
26675-
if (hashToken != this.HashToken || colonToken != this.ColonToken || endOfDirectiveToken != this.EndOfDirectiveToken)
26693+
if (hashToken != this.HashToken || colonToken != this.ColonToken || content != this.Content || endOfDirectiveToken != this.EndOfDirectiveToken)
2667626694
{
26677-
var newNode = SyntaxFactory.IgnoredDirectiveTrivia(hashToken, colonToken, endOfDirectiveToken, isActive);
26695+
var newNode = SyntaxFactory.IgnoredDirectiveTrivia(hashToken, colonToken, content, endOfDirectiveToken, isActive);
2667826696
var diags = GetDiagnostics();
2667926697
if (diags?.Length > 0)
2668026698
newNode = newNode.WithDiagnosticsGreen(diags);
@@ -26688,10 +26706,10 @@ public IgnoredDirectiveTriviaSyntax Update(SyntaxToken hashToken, SyntaxToken co
2668826706
}
2668926707

2669026708
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
26691-
=> new IgnoredDirectiveTriviaSyntax(this.Kind, this.hashToken, this.colonToken, this.endOfDirectiveToken, this.isActive, diagnostics, GetAnnotations());
26709+
=> new IgnoredDirectiveTriviaSyntax(this.Kind, this.hashToken, this.colonToken, this.content, this.endOfDirectiveToken, this.isActive, diagnostics, GetAnnotations());
2669226710

2669326711
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
26694-
=> new IgnoredDirectiveTriviaSyntax(this.Kind, this.hashToken, this.colonToken, this.endOfDirectiveToken, this.isActive, GetDiagnostics(), annotations);
26712+
=> new IgnoredDirectiveTriviaSyntax(this.Kind, this.hashToken, this.colonToken, this.content, this.endOfDirectiveToken, this.isActive, GetDiagnostics(), annotations);
2669526713
}
2669626714

2669726715
internal sealed partial class NullableDirectiveTriviaSyntax : DirectiveTriviaSyntax
@@ -28046,7 +28064,7 @@ public override CSharpSyntaxNode VisitShebangDirectiveTrivia(ShebangDirectiveTri
2804628064
=> node.Update((SyntaxToken)Visit(node.HashToken), (SyntaxToken)Visit(node.ExclamationToken), (SyntaxToken)Visit(node.EndOfDirectiveToken), node.IsActive);
2804728065

2804828066
public override CSharpSyntaxNode VisitIgnoredDirectiveTrivia(IgnoredDirectiveTriviaSyntax node)
28049-
=> node.Update((SyntaxToken)Visit(node.HashToken), (SyntaxToken)Visit(node.ColonToken), (SyntaxToken)Visit(node.EndOfDirectiveToken), node.IsActive);
28067+
=> node.Update((SyntaxToken)Visit(node.HashToken), (SyntaxToken)Visit(node.ColonToken), (SyntaxToken)Visit(node.Content), (SyntaxToken)Visit(node.EndOfDirectiveToken), node.IsActive);
2805028068

2805128069
public override CSharpSyntaxNode VisitNullableDirectiveTrivia(NullableDirectiveTriviaSyntax node)
2805228070
=> node.Update((SyntaxToken)Visit(node.HashToken), (SyntaxToken)Visit(node.NullableKeyword), (SyntaxToken)Visit(node.SettingToken), (SyntaxToken)Visit(node.TargetToken), (SyntaxToken)Visit(node.EndOfDirectiveToken), node.IsActive);
@@ -33332,18 +33350,27 @@ public ShebangDirectiveTriviaSyntax ShebangDirectiveTrivia(SyntaxToken hashToken
3333233350
return new ShebangDirectiveTriviaSyntax(SyntaxKind.ShebangDirectiveTrivia, hashToken, exclamationToken, endOfDirectiveToken, isActive, this.context);
3333333351
}
3333433352

33335-
public IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive)
33353+
public IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken? content, SyntaxToken endOfDirectiveToken, bool isActive)
3333633354
{
3333733355
#if DEBUG
3333833356
if (hashToken == null) throw new ArgumentNullException(nameof(hashToken));
3333933357
if (hashToken.Kind != SyntaxKind.HashToken) throw new ArgumentException(nameof(hashToken));
3334033358
if (colonToken == null) throw new ArgumentNullException(nameof(colonToken));
3334133359
if (colonToken.Kind != SyntaxKind.ColonToken) throw new ArgumentException(nameof(colonToken));
33360+
if (content != null)
33361+
{
33362+
switch (content.Kind)
33363+
{
33364+
case SyntaxKind.StringLiteralToken:
33365+
case SyntaxKind.None: break;
33366+
default: throw new ArgumentException(nameof(content));
33367+
}
33368+
}
3334233369
if (endOfDirectiveToken == null) throw new ArgumentNullException(nameof(endOfDirectiveToken));
3334333370
if (endOfDirectiveToken.Kind != SyntaxKind.EndOfDirectiveToken) throw new ArgumentException(nameof(endOfDirectiveToken));
3334433371
#endif
3334533372

33346-
return new IgnoredDirectiveTriviaSyntax(SyntaxKind.IgnoredDirectiveTrivia, hashToken, colonToken, endOfDirectiveToken, isActive, this.context);
33373+
return new IgnoredDirectiveTriviaSyntax(SyntaxKind.IgnoredDirectiveTrivia, hashToken, colonToken, content, endOfDirectiveToken, isActive, this.context);
3334733374
}
3334833375

3334933376
public NullableDirectiveTriviaSyntax NullableDirectiveTrivia(SyntaxToken hashToken, SyntaxToken nullableKeyword, SyntaxToken settingToken, SyntaxToken? targetToken, SyntaxToken endOfDirectiveToken, bool isActive)
@@ -38654,18 +38681,27 @@ public static ShebangDirectiveTriviaSyntax ShebangDirectiveTrivia(SyntaxToken ha
3865438681
return new ShebangDirectiveTriviaSyntax(SyntaxKind.ShebangDirectiveTrivia, hashToken, exclamationToken, endOfDirectiveToken, isActive);
3865538682
}
3865638683

38657-
public static IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive)
38684+
public static IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken? content, SyntaxToken endOfDirectiveToken, bool isActive)
3865838685
{
3865938686
#if DEBUG
3866038687
if (hashToken == null) throw new ArgumentNullException(nameof(hashToken));
3866138688
if (hashToken.Kind != SyntaxKind.HashToken) throw new ArgumentException(nameof(hashToken));
3866238689
if (colonToken == null) throw new ArgumentNullException(nameof(colonToken));
3866338690
if (colonToken.Kind != SyntaxKind.ColonToken) throw new ArgumentException(nameof(colonToken));
38691+
if (content != null)
38692+
{
38693+
switch (content.Kind)
38694+
{
38695+
case SyntaxKind.StringLiteralToken:
38696+
case SyntaxKind.None: break;
38697+
default: throw new ArgumentException(nameof(content));
38698+
}
38699+
}
3866438700
if (endOfDirectiveToken == null) throw new ArgumentNullException(nameof(endOfDirectiveToken));
3866538701
if (endOfDirectiveToken.Kind != SyntaxKind.EndOfDirectiveToken) throw new ArgumentException(nameof(endOfDirectiveToken));
3866638702
#endif
3866738703

38668-
return new IgnoredDirectiveTriviaSyntax(SyntaxKind.IgnoredDirectiveTrivia, hashToken, colonToken, endOfDirectiveToken, isActive);
38704+
return new IgnoredDirectiveTriviaSyntax(SyntaxKind.IgnoredDirectiveTrivia, hashToken, colonToken, content, endOfDirectiveToken, isActive);
3866938705
}
3867038706

3867138707
public static NullableDirectiveTriviaSyntax NullableDirectiveTrivia(SyntaxToken hashToken, SyntaxToken nullableKeyword, SyntaxToken settingToken, SyntaxToken? targetToken, SyntaxToken endOfDirectiveToken, bool isActive)

src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ public partial class CSharpSyntaxRewriter : CSharpSyntaxVisitor<SyntaxNode?>
22302230
=> node.Update(VisitToken(node.HashToken), VisitToken(node.ExclamationToken), VisitToken(node.EndOfDirectiveToken), node.IsActive);
22312231

22322232
public override SyntaxNode? VisitIgnoredDirectiveTrivia(IgnoredDirectiveTriviaSyntax node)
2233-
=> node.Update(VisitToken(node.HashToken), VisitToken(node.ColonToken), VisitToken(node.EndOfDirectiveToken), node.IsActive);
2233+
=> node.Update(VisitToken(node.HashToken), VisitToken(node.ColonToken), VisitToken(node.Content), VisitToken(node.EndOfDirectiveToken), node.IsActive);
22342234

22352235
public override SyntaxNode? VisitNullableDirectiveTrivia(NullableDirectiveTriviaSyntax node)
22362236
=> node.Update(VisitToken(node.HashToken), VisitToken(node.NullableKeyword), VisitToken(node.SettingToken), VisitToken(node.TargetToken), VisitToken(node.EndOfDirectiveToken), node.IsActive);
@@ -6521,17 +6521,27 @@ public static ShebangDirectiveTriviaSyntax ShebangDirectiveTrivia(bool isActive)
65216521
=> SyntaxFactory.ShebangDirectiveTrivia(SyntaxFactory.Token(SyntaxKind.HashToken), SyntaxFactory.Token(SyntaxKind.ExclamationToken), SyntaxFactory.Token(SyntaxKind.EndOfDirectiveToken), isActive);
65226522

65236523
/// <summary>Creates a new IgnoredDirectiveTriviaSyntax instance.</summary>
6524-
public static IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken endOfDirectiveToken, bool isActive)
6524+
public static IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken hashToken, SyntaxToken colonToken, SyntaxToken content, SyntaxToken endOfDirectiveToken, bool isActive)
65256525
{
65266526
if (hashToken.Kind() != SyntaxKind.HashToken) throw new ArgumentException(nameof(hashToken));
65276527
if (colonToken.Kind() != SyntaxKind.ColonToken) throw new ArgumentException(nameof(colonToken));
6528+
switch (content.Kind())
6529+
{
6530+
case SyntaxKind.StringLiteralToken:
6531+
case SyntaxKind.None: break;
6532+
default: throw new ArgumentException(nameof(content));
6533+
}
65286534
if (endOfDirectiveToken.Kind() != SyntaxKind.EndOfDirectiveToken) throw new ArgumentException(nameof(endOfDirectiveToken));
6529-
return (IgnoredDirectiveTriviaSyntax)Syntax.InternalSyntax.SyntaxFactory.IgnoredDirectiveTrivia((Syntax.InternalSyntax.SyntaxToken)hashToken.Node!, (Syntax.InternalSyntax.SyntaxToken)colonToken.Node!, (Syntax.InternalSyntax.SyntaxToken)endOfDirectiveToken.Node!, isActive).CreateRed();
6535+
return (IgnoredDirectiveTriviaSyntax)Syntax.InternalSyntax.SyntaxFactory.IgnoredDirectiveTrivia((Syntax.InternalSyntax.SyntaxToken)hashToken.Node!, (Syntax.InternalSyntax.SyntaxToken)colonToken.Node!, (Syntax.InternalSyntax.SyntaxToken?)content.Node, (Syntax.InternalSyntax.SyntaxToken)endOfDirectiveToken.Node!, isActive).CreateRed();
65306536
}
65316537

6538+
/// <summary>Creates a new IgnoredDirectiveTriviaSyntax instance.</summary>
6539+
public static IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(SyntaxToken content, bool isActive)
6540+
=> SyntaxFactory.IgnoredDirectiveTrivia(SyntaxFactory.Token(SyntaxKind.HashToken), SyntaxFactory.Token(SyntaxKind.ColonToken), content, SyntaxFactory.Token(SyntaxKind.EndOfDirectiveToken), isActive);
6541+
65326542
/// <summary>Creates a new IgnoredDirectiveTriviaSyntax instance.</summary>
65336543
public static IgnoredDirectiveTriviaSyntax IgnoredDirectiveTrivia(bool isActive)
6534-
=> SyntaxFactory.IgnoredDirectiveTrivia(SyntaxFactory.Token(SyntaxKind.HashToken), SyntaxFactory.Token(SyntaxKind.ColonToken), SyntaxFactory.Token(SyntaxKind.EndOfDirectiveToken), isActive);
6544+
=> SyntaxFactory.IgnoredDirectiveTrivia(SyntaxFactory.Token(SyntaxKind.HashToken), SyntaxFactory.Token(SyntaxKind.ColonToken), default, SyntaxFactory.Token(SyntaxKind.EndOfDirectiveToken), isActive);
65356545

65366546
/// <summary>Creates a new NullableDirectiveTriviaSyntax instance.</summary>
65376547
public static NullableDirectiveTriviaSyntax NullableDirectiveTrivia(SyntaxToken hashToken, SyntaxToken nullableKeyword, SyntaxToken settingToken, SyntaxToken targetToken, SyntaxToken endOfDirectiveToken, bool isActive)

0 commit comments

Comments
 (0)