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

Use collection expression syntax for library import fixer when possible #97806

Merged
merged 3 commits into from
Feb 1, 2024
Merged

Use collection expression syntax for library import fixer when possible #97806

merged 3 commits into from
Feb 1, 2024

Conversation

DoctorKrolic
Copy link
Contributor

Fixes: #96964

We prefer collection expression for C# 12 and above unless user explicitly disabled them via editorconfig rule

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Feb 1, 2024
@ghost
Copy link

ghost commented Feb 1, 2024

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #96964

We prefer collection expression for C# 12 and above unless user explicitly disabled them via editorconfig rule

Author: DoctorKrolic
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

DoctorKrolic and others added 2 commits February 1, 2024 19:20
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

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

return true;
}

private static bool ShouldUseCollectionExpression(Document document, SyntaxTree syntaxTree)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of passing the SyntaxTree down, can we use document.GetOptionsAsync and document.Project.ParseOptions? This will require making more of these methods async, but that's fine since eventually up the chain, the callers here are async already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was purposely avoiding adding async calls to minimize the diff. And document.GetOptionsAsync returns DocumentOptionSet, which is very different from AnalyzerOptions I'm currently using. We can still avoid passing down SyntaxTree if we get it in place with document.GetSyntaxTreeAsync(), but that would require to propogate async, so I'm not sure if this is actually a win. Can you point me to how DocumentOptionSet works and how can I get the same result as from AnalyzerOptions? Or do I need to use GetSyntaxTreeAsync or just leave it as is?

Copy link
Member

Choose a reason for hiding this comment

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

After looking into Roslyn's APIs, they really don't make using well-known options any easier than custom options. We can keep this for now.

return true;
}

private static bool ShouldUseCollectionExpression(Document document, SyntaxTree syntaxTree)
Copy link
Member

Choose a reason for hiding this comment

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

After looking into Roslyn's APIs, they really don't make using well-known options any easier than custom options. We can keep this for now.

@jkoritzinsky jkoritzinsky merged commit 350954c into dotnet:main Feb 1, 2024
116 of 121 checks passed
@DoctorKrolic DoctorKrolic deleted the library-import-collection-expression branch February 2, 2024 07:12
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update code fix for SYSLIB1054 to use a collection expression
3 participants