-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue Detailsnull
|
Marking as a draft. Not ready for review until #72534 is merged and this branch is rebased. |
} | ||
} | ||
|
||
static string Literal(RegexOptions options) | ||
static string Literal(string regexOptionsKey) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
6549876
to
8dab54b
Compare
8dab54b
to
b896c4a
Compare
@joperezr Can you take a look please? Thanks! |
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:
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? |
Sure. I'll try with that approach. |
@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)) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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:
Line 23 in 39d82c9
[ExportCodeFixProvider(LanguageNames.CSharp)] |
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.
src/libraries/System.Text.RegularExpressions/gen/UpgradeToRegexGeneratorCodeFixer.cs
Show resolved
Hide resolved
There was a problem hiding this 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 !
src/libraries/System.Text.RegularExpressions/gen/UpgradeToRegexGeneratorCodeFixer.cs
Outdated
Show resolved
Hide resolved
…xGeneratorCodeFixer.cs
Will merge as soon as Build is green. |
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.