Skip to content

Commit 6e773e2

Browse files
authored
Extensions: xml docs completion (#81274)
Fixes #78770
1 parent ec4f06e commit 6e773e2

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,4 +1129,52 @@ await VerifyItemIsAbsentAsync("""
11291129
"see",
11301130
deletedCharTrigger: 'b');
11311131
}
1132+
1133+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78770")]
1134+
public Task ExtensionBlock_01()
1135+
=> VerifyItemsExistAsync("""
1136+
public static class E
1137+
{
1138+
/// $$
1139+
extension<T>(int i) { }
1140+
}
1141+
""", """
1142+
typeparam name="T"
1143+
""", """
1144+
param name="i"
1145+
""",
1146+
"summary");
1147+
1148+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78770")]
1149+
public Task ExtensionBlock_02()
1150+
=> VerifyItemsExistAsync("""
1151+
public static class E
1152+
{
1153+
/// <summary> $$ </summary>
1154+
extension<T>(int i)
1155+
{
1156+
}
1157+
}
1158+
""", """
1159+
paramref name="i"
1160+
""", """
1161+
typeparamref name="T"
1162+
""");
1163+
1164+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78770")]
1165+
public Task ExtensionBlock_03()
1166+
=> VerifyItemsExistAsync("""
1167+
public static class E
1168+
{
1169+
extension<T>(int i)
1170+
{
1171+
/// <summary> $$ </summary>
1172+
void M() { }
1173+
}
1174+
}
1175+
""", """
1176+
paramref name="i"
1177+
""", """
1178+
typeparamref name="T"
1179+
""");
11321180
}

src/EditorFeatures/CSharpTest/DocumentationComments/DocumentationCommentTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ class C
3333
}
3434
""");
3535

36+
[WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/78770")]
37+
public void TypingCharacter_Extension()
38+
=> VerifyTypingCharacter("""
39+
static class C
40+
{
41+
//$$
42+
extension<T>(int i) { }
43+
}
44+
""", """
45+
static class C
46+
{
47+
/// <summary>
48+
/// $$
49+
/// </summary>
50+
/// <typeparam name="T"></typeparam>
51+
/// <param name="i"></param>
52+
extension<T>(int i) { }
53+
}
54+
""");
55+
3656
[WpfFact]
3757
public void TypingCharacter_Record()
3858
=> VerifyTypingCharacter("""

src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ protected override ImmutableArray<IParameterSymbol> GetParameters(ISymbol declar
399399
{
400400
declaredParameters = delegateInvokeParameters;
401401
}
402+
else if (namedTypeSymbol.IsExtension && namedTypeSymbol.ExtensionParameter is { } extensionParameter)
403+
{
404+
declaredParameters = [extensionParameter];
405+
}
402406
}
403407

404408
return declaredParameters;

src/Features/CSharp/Portable/DocumentationComments/CSharpDocumentationCommentSnippetService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected override bool SupportsDocumentationComments(MemberDeclarationSyntax me
5656
case SyntaxKind.EventFieldDeclaration:
5757
case SyntaxKind.OperatorDeclaration:
5858
case SyntaxKind.ConversionOperatorDeclaration:
59+
case SyntaxKind.ExtensionBlockDeclaration:
5960
return true;
6061

6162
default:

src/Features/Core/Portable/Completion/Providers/AbstractDocCommentCompletionProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Threading;
1010
using System.Threading.Tasks;
11+
using Microsoft.CodeAnalysis.CodeFixes;
1112
using Microsoft.CodeAnalysis.PooledObjects;
1213
using Microsoft.CodeAnalysis.Shared.Extensions;
1314
using Microsoft.CodeAnalysis.Text;
@@ -150,6 +151,11 @@ protected IEnumerable<CompletionItem> GetNestedItems(ISymbol? symbol, bool inclu
150151
.Concat(GetTypeParamRefItems(symbol));
151152
}
152153

154+
if (symbol is { ContainingSymbol: INamedTypeSymbol { IsExtension: true } extension })
155+
{
156+
items = items.Concat(GetParamRefItems(extension));
157+
}
158+
153159
if (includeKeywords)
154160
{
155161
items = items.Concat(GetKeywordNames().Select(CreateLangwordCompletionItem));

0 commit comments

Comments
 (0)