Skip to content

Commit ac301e2

Browse files
authored
Add signature help support for ref struct interfaces (#73624)
The selected display part building code for method constraints in signature help had not yet been modified to support ITypeParameterSymbol.AllowsRefLikeType This is in support of the "allows ref struct" on interfaces feature outlined here: #72124 This ref structs for interfaces feature was merged via this PR: #73567
1 parent a2d6fb1 commit ac301e2

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameSignatureHelpProviderTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,30 @@ void Goo()
451451
await TestAsync(markup, expectedOrderedItems);
452452
}
453453

454+
[Fact]
455+
public async Task DeclaringGenericTypeWithConstraintsAllowRefStruct()
456+
{
457+
var markup = """
458+
class G<S> where S : allows ref struct
459+
{ };
460+
461+
class C
462+
{
463+
void Goo()
464+
{
465+
[|G<$$|]>
466+
}
467+
}
468+
""";
469+
470+
var expectedOrderedItems = new List<SignatureHelpTestItem>
471+
{
472+
new SignatureHelpTestItem("G<S> where S : allows ref struct", string.Empty, string.Empty, currentParameterIndex: 0)
473+
};
474+
475+
await TestAsync(markup, expectedOrderedItems);
476+
}
477+
454478
#endregion
455479

456480
#region "Generic member invocation"

src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,22 @@ private static IList<SymbolDisplayPart> GetSelectedDisplayParts(
284284
parts.Add(Keyword(SyntaxKind.NewKeyword));
285285
parts.Add(Punctuation(SyntaxKind.OpenParenToken));
286286
parts.Add(Punctuation(SyntaxKind.CloseParenToken));
287+
needComma = true;
288+
}
289+
290+
if (typeParam.AllowsRefLikeType)
291+
{
292+
if (needComma)
293+
{
294+
parts.Add(Punctuation(SyntaxKind.CommaToken));
295+
parts.Add(Space());
296+
}
297+
298+
parts.Add(Keyword(SyntaxKind.AllowsKeyword));
299+
parts.Add(Space());
300+
parts.Add(Keyword(SyntaxKind.RefKeyword));
301+
parts.Add(Space());
302+
parts.Add(Keyword(SyntaxKind.StructKeyword));
287303
}
288304
}
289305

@@ -293,6 +309,7 @@ private static IList<SymbolDisplayPart> GetSelectedDisplayParts(
293309
private static bool TypeParameterHasConstraints(ITypeParameterSymbol typeParam)
294310
{
295311
return !typeParam.ConstraintTypes.IsDefaultOrEmpty || typeParam.HasConstructorConstraint ||
296-
typeParam.HasReferenceTypeConstraint || typeParam.HasValueTypeConstraint;
312+
typeParam.HasReferenceTypeConstraint || typeParam.HasValueTypeConstraint ||
313+
typeParam.AllowsRefLikeType;
297314
}
298315
}

src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/SignatureComparer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ private bool HaveSameConstraints(ITypeParameterSymbol typeParameter1, ITypeParam
223223
{
224224
if (typeParameter1.HasConstructorConstraint != typeParameter2.HasConstructorConstraint ||
225225
typeParameter1.HasReferenceTypeConstraint != typeParameter2.HasReferenceTypeConstraint ||
226-
typeParameter1.HasValueTypeConstraint != typeParameter2.HasValueTypeConstraint)
226+
typeParameter1.HasValueTypeConstraint != typeParameter2.HasValueTypeConstraint ||
227+
typeParameter1.AllowsRefLikeType != typeParameter2.AllowsRefLikeType)
227228
{
228229
return false;
229230
}

0 commit comments

Comments
 (0)