From cbdee66fd5baf3219f7afde62ebf5a4e1b646134 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 06:37:37 -0400 Subject: [PATCH 01/11] Add test cases --- .../CSharp/Test/F1Help/F1HelpTests.cs | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs index 48a2dd6de7eda..689bdf558e0c8 100644 --- a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs +++ b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs @@ -817,5 +817,113 @@ 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 TestDefaultValueInsideSwitch() + { + 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 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"); + } } } From 93e5d20ca5d00d403ed78886cccc045b54f3f35a Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 06:59:55 -0400 Subject: [PATCH 02/11] Add F1_help test cases for default keyword --- .../CSharp/Test/F1Help/F1HelpTests.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs index 689bdf558e0c8..fbea1af41c3cb 100644 --- a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs +++ b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs @@ -838,7 +838,7 @@ void M1(int parameter) [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] [Fact, Trait(Traits.Feature, Traits.Features.F1Help)] - public async Task TestDefaultValueInsideSwitch() + public async Task TestDefaultLiteralExpressionInsideSwitch() { await Test_KeywordAsync( @"class C @@ -854,6 +854,24 @@ void M1(int parameter) }", "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() From e743fa77914fb2668ece491c80396aab2b889bca Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 07:01:32 -0400 Subject: [PATCH 03/11] Identify default switch case --- .../Impl/LanguageService/CSharpHelpContextService.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index 5aa0bc278d781..32a7e1175df09 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -352,6 +352,14 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService } } + if (token.IsKind(SyntaxKind.DefaultKeyword)) { + if (token.Parent is DefaultSwitchLabelSyntax) + { + text = Keyword("defaultcase"); + return true; + } + } + if (token.IsKeyword()) { text = Keyword(token.Text); From 748ba17ae1cb234b04d625ad0efd27db36d241e1 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 07:01:42 -0400 Subject: [PATCH 04/11] Identify default expression --- .../CSharp/Impl/LanguageService/CSharpHelpContextService.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index 32a7e1175df09..83a8ff8253257 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -358,6 +358,12 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService text = Keyword("defaultcase"); return true; } + + if (token.Parent is DefaultExpressionSyntax) + { + text = Keyword("defaultvalue"); + return true; + } } if (token.IsKeyword()) From 5eba0820bad790be642a6b442b97a4047f6360e5 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 07:14:02 -0400 Subject: [PATCH 05/11] Identify default literal expression --- .../CSharp/Impl/LanguageService/CSharpHelpContextService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index 83a8ff8253257..96d4bd035a23a 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -359,7 +359,7 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService return true; } - if (token.Parent is DefaultExpressionSyntax) + if (token.Parent is DefaultExpressionSyntax || token.Parent is LiteralExpressionSyntax) { text = Keyword("defaultvalue"); return true; From 0b0afdc364ba7ed9108077abd68c3899443b8c03 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 10:15:45 -0400 Subject: [PATCH 06/11] Proper C# curly placement --- .../CSharp/Impl/LanguageService/CSharpHelpContextService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index 96d4bd035a23a..b6844f9772fe8 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -352,7 +352,8 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService } } - if (token.IsKind(SyntaxKind.DefaultKeyword)) { + if (token.IsKind(SyntaxKind.DefaultKeyword)) + { if (token.Parent is DefaultSwitchLabelSyntax) { text = Keyword("defaultcase"); From e00dd92c17e66b08059475ba08ca0239e4f32693 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 12:52:18 -0400 Subject: [PATCH 07/11] Simplify with Pattern Combinator --- .../CSharp/Impl/LanguageService/CSharpHelpContextService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index b6844f9772fe8..716f0be7322d9 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -360,7 +360,7 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService return true; } - if (token.Parent is DefaultExpressionSyntax || token.Parent is LiteralExpressionSyntax) + if (token.Parent is DefaultExpressionSyntax or LiteralExpressionSyntax) { text = Keyword("defaultvalue"); return true; From e6c49c55ee0a26a3f80ef84fa53f02222ad7f855 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 20:47:39 -0400 Subject: [PATCH 08/11] Simplify matching of `default` cases --- .../Impl/LanguageService/CSharpHelpContextService.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index 716f0be7322d9..88361846d49be 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -358,11 +358,8 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService { text = Keyword("defaultcase"); return true; - } - - if (token.Parent is DefaultExpressionSyntax or LiteralExpressionSyntax) - { - text = Keyword("defaultvalue"); + } else { + text = Keyword(token.Text); return true; } } From 245c6f89a9eda890899c85d0aa93e55329386630 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Sun, 11 Oct 2020 20:52:36 -0400 Subject: [PATCH 09/11] Simply let normal Keyword case fall through --- .../LanguageService/CSharpHelpContextService.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index 88361846d49be..f2a1043906468 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -352,16 +352,9 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService } } - if (token.IsKind(SyntaxKind.DefaultKeyword)) - { - if (token.Parent is DefaultSwitchLabelSyntax) - { - text = Keyword("defaultcase"); - return true; - } else { - text = Keyword(token.Text); - return true; - } + if (token.IsKind(SyntaxKind.DefaultKeyword) && token.Parent is DefaultSwitchLabelSyntax) { + text = Keyword("defaultcase"); + return true; } if (token.IsKeyword()) From 214b82d41f1c9f45d04c478814d9d9aa71bdae67 Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Mon, 12 Oct 2020 12:21:48 -0400 Subject: [PATCH 10/11] Fix test expectations --- .../CSharp/Test/F1Help/F1HelpTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs index fbea1af41c3cb..79cc4e81b6b3f 100644 --- a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs +++ b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs @@ -851,7 +851,7 @@ void M1(int parameter) break; } } -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -869,7 +869,7 @@ void M1(int parameter) break; } } -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -880,7 +880,7 @@ await Test_KeywordAsync( @"class C { int field = defa[||]ult; -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -891,7 +891,7 @@ await Test_KeywordAsync( @"class C { int field = defa[||]ult(int); -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -903,7 +903,7 @@ await Test_KeywordAsync( { void M1(int parameter = defa[||]ult) { } -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -915,7 +915,7 @@ await Test_KeywordAsync( { void M1(int parameter = defa[||]ult(int)) { } -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -928,7 +928,7 @@ await Test_KeywordAsync( void M1() { M2(defa[||]ult); } -}", "defaultvalue"); +}", "default"); } [WorkItem(48392, "https://github.com/dotnet/roslyn/issues/48392")] @@ -941,7 +941,7 @@ await Test_KeywordAsync( void M1() { M2(defa[||]ult(int)); } -}", "defaultvalue"); +}", "default"); } } } From eb2e2578aadc7a880685a9f1a22358a41f568d1d Mon Sep 17 00:00:00 2001 From: Jon Senchyna Date: Mon, 12 Oct 2020 20:18:42 -0400 Subject: [PATCH 11/11] Fix curly placement --- .../CSharp/Impl/LanguageService/CSharpHelpContextService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index f2a1043906468..efb5510af0c3e 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -352,7 +352,8 @@ private static bool TryGetTextForKeyword(SyntaxToken token, ISyntaxFactsService } } - if (token.IsKind(SyntaxKind.DefaultKeyword) && token.Parent is DefaultSwitchLabelSyntax) { + if (token.IsKind(SyntaxKind.DefaultKeyword) && token.Parent is DefaultSwitchLabelSyntax) + { text = Keyword("defaultcase"); return true; }