Skip to content

Commit

Permalink
Add signature help support for ref struct interfaces (#73624)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ToddGrun authored May 22, 2024
1 parent a2d6fb1 commit ac301e2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,30 @@ void Goo()
await TestAsync(markup, expectedOrderedItems);
}

[Fact]
public async Task DeclaringGenericTypeWithConstraintsAllowRefStruct()
{
var markup = """
class G<S> where S : allows ref struct
{ };
class C
{
void Goo()
{
[|G<$$|]>
}
}
""";

var expectedOrderedItems = new List<SignatureHelpTestItem>
{
new SignatureHelpTestItem("G<S> where S : allows ref struct", string.Empty, string.Empty, currentParameterIndex: 0)
};

await TestAsync(markup, expectedOrderedItems);
}

#endregion

#region "Generic member invocation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ private static IList<SymbolDisplayPart> GetSelectedDisplayParts(
parts.Add(Keyword(SyntaxKind.NewKeyword));
parts.Add(Punctuation(SyntaxKind.OpenParenToken));
parts.Add(Punctuation(SyntaxKind.CloseParenToken));
needComma = true;
}

if (typeParam.AllowsRefLikeType)
{
if (needComma)
{
parts.Add(Punctuation(SyntaxKind.CommaToken));
parts.Add(Space());
}

parts.Add(Keyword(SyntaxKind.AllowsKeyword));
parts.Add(Space());
parts.Add(Keyword(SyntaxKind.RefKeyword));
parts.Add(Space());
parts.Add(Keyword(SyntaxKind.StructKeyword));
}
}

Expand All @@ -293,6 +309,7 @@ private static IList<SymbolDisplayPart> GetSelectedDisplayParts(
private static bool TypeParameterHasConstraints(ITypeParameterSymbol typeParam)
{
return !typeParam.ConstraintTypes.IsDefaultOrEmpty || typeParam.HasConstructorConstraint ||
typeParam.HasReferenceTypeConstraint || typeParam.HasValueTypeConstraint;
typeParam.HasReferenceTypeConstraint || typeParam.HasValueTypeConstraint ||
typeParam.AllowsRefLikeType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private bool HaveSameConstraints(ITypeParameterSymbol typeParameter1, ITypeParam
{
if (typeParameter1.HasConstructorConstraint != typeParameter2.HasConstructorConstraint ||
typeParameter1.HasReferenceTypeConstraint != typeParameter2.HasReferenceTypeConstraint ||
typeParameter1.HasValueTypeConstraint != typeParameter2.HasValueTypeConstraint)
typeParameter1.HasValueTypeConstraint != typeParameter2.HasValueTypeConstraint ||
typeParameter1.AllowsRefLikeType != typeParameter2.AllowsRefLikeType)
{
return false;
}
Expand Down

0 comments on commit ac301e2

Please sign in to comment.