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 analyzer/fixer to suggest changing code fluent collection building to a collection expression #69580

Merged

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Aug 17, 2023

Part of #69473

Finds code like: ImmutableArray<int>.Empty.AddRange(x).AddRange(y).ToXXX() (and many patterns like that) and offers to convert to code like [..y, ..y].

This works for varying patterns of Add/AddRange as well as Concat (on a reified list).

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 17, 2023
@CyrusNajmabadi
Copy link
Member Author

@akhera99 for review. thanks!

var conversion = speculationAnalyzer.SpeculativeSemanticModel.GetConversion(speculationAnalyzer.ReplacedExpression, cancellationToken);
if (conversion.IsIdentity)
Copy link
Member Author

Choose a reason for hiding this comment

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

@cston this appears to be an error. Once this merged, i'll open a bug on this.

}

return node;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this improved indentation tracking in a few more situations.

@@ -927,4 +926,87 @@ void M()
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
}.RunAsync();
}

[Fact]
Copy link
Member Author

Choose a reason for hiding this comment

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

beefed up testing in a few existing features.

this.SyntaxFacts.GetNameAndArityOfSimpleName(memberName, out var name, out var arity);

if (arity != 0 || !Equals(name, methodName))
return false;
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 the fast checks up.

@CyrusNajmabadi
Copy link
Member Author

@akhera99 ptal.

@CyrusNajmabadi CyrusNajmabadi merged commit c51503b into dotnet:main Aug 22, 2023
@ghost ghost added this to the Next milestone Aug 22, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the useCollectionExpressionForFluent branch August 22, 2023 17:28
@dibarbet dibarbet modified the milestones: Next, 17.8 P2 Aug 28, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants