Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,31 @@ private static bool TryGetTextForKeyword(SyntaxToken token, [NotNullWhen(true)]
}
}

if (token.IsKind(SyntaxKind.DefaultKeyword) && token.Parent is DefaultSwitchLabelSyntax)
if (token.IsKind(SyntaxKind.DefaultKeyword))
{
text = Keyword("defaultcase");
return true;
if (token.Parent is DefaultSwitchLabelSyntax)
{
text = Keyword("defaultcase");
return true;
}

Copy link
Member

@Youssef1313 Youssef1313 Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated below

Suggested change
if (token.Parent is DefaultSwitchLabelSyntax)
{
text = Keyword("defaultcase");
return true;
}

if (token.Parent is DefaultConstraintSyntax)
{
text = Keyword("defaultconstraint");
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling goto default (not sure which doc page is suitable).

Also #line default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions. Added

I'll let @BillWagner decide, but for goto default we could always go to the page for switch and for #line default we could go to the section for #line preprocessing directive.

Copy link
Member

@Youssef1313 Youssef1313 Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could go to the section

We can't go to a specific section, unfortunately.

But I'll update the page on dotnet/docs to have the new F1 keyword. Edit: Opened dotnet/docs#32197


if (token.Parent is DefaultSwitchLabelSyntax or GotoStatementSyntax)
{
text = Keyword("defaultcase");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will redirect to https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/selection-statements

Currently there doesn't seem to be anything about goto default there, but I opened dotnet/docs#32196

return true;
}

if (token.Parent is LineDirectiveTriviaSyntax)
{
text = Keyword("defaultline");
return true;
}
Comment on lines +468 to +472
Copy link
Member

@Youssef1313 Youssef1313 Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillWagner Where should this go? The proposal? Or is there any conceptual doc for it? Just saw #65229 (comment)

}

if (token.IsKind(SyntaxKind.ClassKeyword) && token.Parent is ClassOrStructConstraintSyntax)
Expand Down
63 changes: 63 additions & 0 deletions src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,5 +1739,68 @@ public class C
}
""", "required");
}

[Fact]
public async Task TestDefaultConstraint()
{
await Test_KeywordAsync("""
public class Base
{
virtual void M<T>(T? t) { }
}
public class C
{
override void M<T>() where T : def[||]ault { }
}
""", expectedText: "defaultconstraint");
}

[Fact]
public async Task TestDefaultCase()
{
await Test_KeywordAsync("""
public class C
{
void M(object o)
{
switch (o)
{
case 1:
goto def[||]ault;
default:
return;
}
}
}
""", expectedText: "defaultcase");
}

[Fact]
public async Task TestGotoDefault()
{
await Test_KeywordAsync("""
public class C
{
void M(object o)
{
switch (o)
{
case 1:
goto default;
def[||]ault:
return;
}
}
}
""", expectedText: "defaultcase");
}

[Fact]
public async Task TestLineDefault()
{
await Test_KeywordAsync("""
#line def[||]ault
""", expectedText: "defaultline");
}
}
}