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

Simplify UpgradeToRegexGenerator #72538

Merged
merged 5 commits into from
Jul 26, 2022
Merged

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Jul 20, 2022

Previously, analyzer reported argument indices in its properties. Then codefix will get the argument values from the indices in GetNode. I changed the analyzer to report the values directly, which simplifies things a little bit.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 20, 2022
@ghost
Copy link

ghost commented Jul 20, 2022

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

Issue Details

null

Author: Youssef1313
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: -

@Youssef1313
Copy link
Member Author

Marking as a draft. Not ready for review until #72534 is merged and this branch is rebased.

@Youssef1313 Youssef1313 marked this pull request as draft July 20, 2022 18:44
}
}

static string Literal(RegexOptions options)
static string Literal(string regexOptionsKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be renamed to something like FormatRegexOptions. It's not clear what it does by the name and parameter type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably stringifiedRegexOptions to make it clear this is a RegexOptions that we called ToString on?

@Youssef1313 Youssef1313 force-pushed the simplify-regex-gen branch 2 times, most recently from 6549876 to 8dab54b Compare July 21, 2022 04:31
@Youssef1313 Youssef1313 marked this pull request as ready for review July 21, 2022 04:33
@Youssef1313
Copy link
Member Author

@joperezr Can you take a look please? Thanks!

@joperezr
Copy link
Member

Thanks for the PR @Youssef1313. Since you are changing this, one of the comments from the original PR that added the analyzer was particularly suggesting that ideally we shouldn't have the analyzer send any info into the fixer if possible in order to have both be easier to understand and maintain. Here is the relevant part of the comment by @mavasani:

Is there a reason to add this property bag to the diagnostic instead of computing all the required information in the fixer itself? Given the diagnostic location, the fixer can fetch the required syntax node from the location using root.FindNode(span) API. You can get the semantic model from the document using document.GetSemanticModelAsync API and then use semanticModel.GetOperation(node) API to get to the IInvocationOperation.
...
We generally don't recommend using such a property bag unless needed as you are now adding an additional dependency between the analyzer and fixer internals, which might make it more harder to maintain or understand.

I think if we are changing this now, we should re-evaluate that comment and perhaps moving the logic of grabbing the values out to the fixer itself. Thoughts?

@Youssef1313
Copy link
Member Author

Sure. I'll try with that approach.

@Youssef1313
Copy link
Member Author

@joperezr I applied the suggestion. The PR is ready for another look.

// Validate that arguments pattern and options are constant and timeout was not passed in.
if (!TryValidateParametersAndExtractArgumentIndices(invocationOperation.Arguments, ref patternArgumentIndex, ref optionsArgumentIndex))
if (!TryValidateParametersAndExtractArgumentIndices(invocationOperation.Arguments))
Copy link
Member

Choose a reason for hiding this comment

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

Small NIT: The name of the method is technically not accurate any longer, now we are only doing validation of the Parameters so we could rename to ValidateParameters

@@ -24,7 +25,7 @@ namespace System.Text.RegularExpressions.Generator
/// Roslyn code fixer that will listen to SysLIB1046 diagnostics and will provide a code fix which onboards a particular Regex into
/// source generation.
/// </summary>
[ExportCodeFixProvider(LanguageNames.CSharp)]
[ExportCodeFixProvider(LanguageNames.CSharp), Shared]
Copy link
Member

Choose a reason for hiding this comment

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

Looks like in other similar places we aren't adding this attribute, like:

I'm not saying adding the attribute is wrong, but it also isn't very related to this PR so we should probably live that to a follow up PR.

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @Youssef1313 !

@joperezr
Copy link
Member

Will merge as soon as Build is green.

@joperezr joperezr merged commit 891cc3a into dotnet:main Jul 26, 2022
@Youssef1313 Youssef1313 deleted the simplify-regex-gen branch July 27, 2022 00:34
@ghost ghost locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.RegularExpressions 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.

3 participants