Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat record positional parameters as properties #48329

Merged
merged 6 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ public class DeclarationNameCompletionProviderTests : AbstractCSharpCompletionPr
internal override Type GetCompletionProviderType()
=> typeof(DeclarationNameCompletionProvider);

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(48310, "https://github.com/dotnet/roslyn/issues/48310")]
public async Task TreatRecordPositionalParameterAsProperty()
{
var markup = @"
public class MyClass
{
}

public record R(MyClass $$
";
await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic);
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task NameWithOnlyType1()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ internal struct NameDeclarationInfo
private static readonly ImmutableArray<SymbolKindOrTypeKind> s_parameterSyntaxKind =
ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Parameter));

private static readonly ImmutableArray<SymbolKindOrTypeKind> s_propertySyntaxKind =
ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Property));

public NameDeclarationInfo(
ImmutableArray<SymbolKindOrTypeKind> possibleSymbolKinds,
Accessibility? accessibility,
Expand Down Expand Up @@ -155,7 +158,7 @@ private static bool IsPossibleVariableOrLocalMethodDeclaration(
token, semanticModel,
e => e.Expression,
_ => default,
_ => ImmutableArray.Create(
(_, _) => ImmutableArray.Create(
new SymbolKindOrTypeKind(SymbolKind.Local),
new SymbolKindOrTypeKind(MethodKind.LocalFunction)),
cancellationToken);
Expand All @@ -170,7 +173,7 @@ private static bool IsPropertyDeclaration(SyntaxToken token, SemanticModel seman
semanticModel,
m => m.Type,
m => m.Modifiers,
GetPossibleMemberDeclarations,
(_, m) => GetPossibleMemberDeclarations(m),
cancellationToken);

return result.Type != null;
Expand All @@ -184,7 +187,7 @@ private static bool IsMethodDeclaration(SyntaxToken token, SemanticModel semanti
semanticModel,
m => m.ReturnType,
m => m.Modifiers,
GetPossibleMemberDeclarations,
(_, m) => GetPossibleMemberDeclarations(m),
cancellationToken);

return result.Type != null;
Expand Down Expand Up @@ -247,7 +250,7 @@ private static NameDeclarationInfo IsLastTokenOfType<TSyntaxNode>(
SemanticModel semanticModel,
Func<TSyntaxNode, SyntaxNode> typeSyntaxGetter,
Func<TSyntaxNode, SyntaxTokenList> modifierGetter,
Func<DeclarationModifiers, ImmutableArray<SymbolKindOrTypeKind>> possibleDeclarationComputer,
Func<TSyntaxNode, DeclarationModifiers, ImmutableArray<SymbolKindOrTypeKind>> possibleDeclarationComputer,
CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
{
if (!IsPossibleTypeToken(token))
Expand All @@ -270,7 +273,7 @@ private static NameDeclarationInfo IsLastTokenOfType<TSyntaxNode>(
var modifiers = modifierGetter(target);

return new NameDeclarationInfo(
possibleDeclarationComputer(GetDeclarationModifiers(modifiers)),
possibleDeclarationComputer(target, GetDeclarationModifiers(modifiers)),
GetAccessibility(modifiers),
GetDeclarationModifiers(modifiers),
semanticModel.GetTypeInfo(typeSyntax, cancellationToken).Type,
Expand All @@ -294,7 +297,7 @@ private static bool IsIncompleteMemberDeclaration(SyntaxToken token, SemanticMod
result = IsLastTokenOfType<IncompleteMemberSyntax>(token, semanticModel,
i => i.Type,
i => i.Modifiers,
GetPossibleMemberDeclarations,
(_, m) => GetPossibleMemberDeclarations(m),
cancellationToken);
return result.Type != null;
}
Expand All @@ -305,7 +308,7 @@ private static bool IsLocalFunctionDeclaration(SyntaxToken token, SemanticModel
result = IsLastTokenOfType<LocalFunctionStatementSyntax>(token, semanticModel,
typeSyntaxGetter: f => f.ReturnType,
modifierGetter: f => f.Modifiers,
possibleDeclarationComputer: GetPossibleLocalDeclarations,
possibleDeclarationComputer: (_, m) => GetPossibleLocalDeclarations(m),
cancellationToken);
return result.Type != null;
}
Expand Down Expand Up @@ -353,7 +356,7 @@ private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticMode
f is ForEachVariableStatementSyntax forEachVariableStatement ? forEachVariableStatement.Variable :
null, // Return null to bail out.
modifierGetter: f => default,
possibleDeclarationComputer: d => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)),
possibleDeclarationComputer: (_, d) => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)),
cancellationToken);
return result.Type != null;
}
Expand Down Expand Up @@ -384,7 +387,7 @@ private static bool IsParameterDeclaration(SyntaxToken token, SemanticModel sema
token, semanticModel,
p => p.Type,
_ => default,
_ => s_parameterSyntaxKind,
(parameterSyntax, _) => parameterSyntax.Parent.IsParentKind(SyntaxKind.RecordDeclaration) ? s_propertySyntaxKind : s_parameterSyntaxKind,
cancellationToken);
return result.Type != null;
}
Expand All @@ -399,7 +402,7 @@ private static bool IsPatternMatching(SyntaxToken token, SemanticModel semanticM
token, semanticModel,
b => b.Right,
_ => default,
_ => s_parameterSyntaxKind,
(_, _) => s_parameterSyntaxKind,
cancellationToken);
}
else if (token.Parent.IsParentKind(SyntaxKind.CaseSwitchLabel))
Expand All @@ -408,7 +411,7 @@ private static bool IsPatternMatching(SyntaxToken token, SemanticModel semanticM
token, semanticModel,
b => b.Value,
_ => default,
_ => s_parameterSyntaxKind,
(_, _) => s_parameterSyntaxKind,
cancellationToken);
}
else if (token.Parent.IsParentKind(SyntaxKind.DeclarationPattern))
Expand All @@ -417,7 +420,7 @@ private static bool IsPatternMatching(SyntaxToken token, SemanticModel semanticM
token, semanticModel,
b => b.Type,
_ => default,
_ => s_parameterSyntaxKind,
(_, _) => s_parameterSyntaxKind,
cancellationToken);
}

Expand Down