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

Add more cases supported by 'use collection expression' #75879

Merged
merged 14 commits into from
Nov 14, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #75870

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner November 13, 2024 01:27
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 13, 2024
@@ -20,11 +20,6 @@ internal sealed partial class CSharpUseCollectionExpressionForCreateDiagnosticAn
IDEDiagnosticIds.UseCollectionExpressionForCreateDiagnosticId,
EnforceOnBuildValues.UseCollectionExpressionForCreate)
{
public const string UnwrapArgument = nameof(UnwrapArgument);

private static readonly ImmutableDictionary<string, string?> s_unwrapArgumentProperties =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to common location

var properties = unwrapArgument ? s_unwrapArgumentProperties : ImmutableDictionary<string, string?>.Empty;
if (changesSemantics)
properties = properties.Add(UseCollectionInitializerHelpers.ChangesSemanticsName, "");
var properties = GetDiagnosticProperties(unwrapArgument, useSpread, changesSemantics);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to common location

nameof(ParallelEnumerable),
nameof(ParallelQuery),
// Special internal runtime interface that is optimized for fast path conversions of collections.
"IIListProvider"];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to common location

Implements(type, compilation.IReadOnlyListOfTType());
}

bool IsIterable(ExpressionSyntax expression)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to common location

internal sealed partial class CSharpUseCollectionExpressionForNewDiagnosticAnalyzer()
: AbstractCSharpUseCollectionExpressionDiagnosticAnalyzer(
IDEDiagnosticIds.UseCollectionExpressionForNewDiagnosticId,
EnforceOnBuildValues.UseCollectionExpressionForNew)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports converting new List<...>(x) to [.. x]

{
var argExpression = arguments[0].Expression;
if (argExpression
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to helper.

@CyrusNajmabadi CyrusNajmabadi changed the title Add more cases supported by 'use collection expressoin' Add more cases supported by 'use collection expression' Nov 13, 2024
@CyrusNajmabadi
Copy link
Member Author

@akhera99 @dibarbet ptal.

{
void M()
{
const bool shouldParallelize = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71145")]
public async Task TestNotInParallelEnumerable2()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Not" in the name makes me think it should not convert to a collection expression

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. We didn't update hte parallel one, only the non parallel one :)

@CyrusNajmabadi CyrusNajmabadi merged commit 747210f into dotnet:main Nov 14, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend the "Use collection expression" suggestion to scenarios requiring the spread operator
3 participants