diff --git a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs index a34675c50bf4d..431ae7d7a87d2 100644 --- a/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs +++ b/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs @@ -451,10 +451,25 @@ 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 DefaultConstraintSyntax) + { + text = Keyword("defaultconstraint"); + return true; + } + + if (token.Parent is DefaultSwitchLabelSyntax or GotoStatementSyntax) + { + text = Keyword("defaultcase"); + return true; + } + + if (token.Parent is LineDirectiveTriviaSyntax) + { + text = Keyword("defaultline"); + return true; + } } if (token.IsKind(SyntaxKind.ClassKeyword) && token.Parent is ClassOrStructConstraintSyntax) diff --git a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs index d084b03a1e4d4..071a2c5c020a2 100644 --- a/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs +++ b/src/VisualStudio/CSharp/Test/F1Help/F1HelpTests.cs @@ -1739,5 +1739,68 @@ public class C } """, "required"); } + + [Fact] + public async Task TestDefaultConstraint() + { + await Test_KeywordAsync(""" + public class Base + { + virtual void M(T? t) { } + } + public class C + { + override void M() 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"); + } } }