Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update F1 Keywords to differentiate between semantics of default keyword #48500

Merged
merged 11 commits into from
Oct 13, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService
}
}

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

if (token.IsKeyword())
{
text = Keyword(token.Text);
Expand Down
126 changes: 126 additions & 0 deletions src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,5 +817,131 @@ bool goo(bool x)
}
}", "!");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultSwitchCase()
{
await Test_KeywordAsync(
@"class C
{
void M1(int parameter)
{
switch(parameter) {
defa[||]ult:
parameter = default;
break;
}
}
}", "defaultcase");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultLiteralExpressionInsideSwitch()
{
await Test_KeywordAsync(
@"class C
{
void M1(int parameter)
{
switch(parameter) {
default:
parameter = defa[||]ult;
break;
}
}
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultExpressionInsideSwitch()
{
await Test_KeywordAsync(
@"class C
{
void M1(int parameter)
{
switch(parameter) {
default:
parameter = defa[||]ult(int);
break;
}
}
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultLiteralExpression()
{
await Test_KeywordAsync(
@"class C
{
int field = defa[||]ult;
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultExpression()
{
await Test_KeywordAsync(
@"class C
{
int field = defa[||]ult(int);
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultLiteralExpressionInOptionalParameter()
{
await Test_KeywordAsync(
@"class C
{
void M1(int parameter = defa[||]ult) {
}
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultExpressionInOptionalParameter()
{
await Test_KeywordAsync(
@"class C
{
void M1(int parameter = defa[||]ult(int)) {
}
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultLiteralExpressionInMethodCall()
{
await Test_KeywordAsync(
@"class C
{
void M1() {
M2(defa[||]ult);
}
}", "defaultvalue");
}

[WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")]
[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestDefaultExpressionInMethodCall()
{
await Test_KeywordAsync(
@"class C
{
void M1() {
M2(defa[||]ult(int));
}
}", "defaultvalue");
}
}
}