UseInferredMemberName: use one code style option and share more code#23506
UseInferredMemberName: use one code style option and share more code#23506jcouv merged 2 commits intodotnet:masterfrom
Conversation
| => context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.NameColon, SyntaxKind.NameEquals); | ||
|
|
||
| private void AnalyzeSyntax(SyntaxNodeAnalysisContext context) | ||
| override protected void LanguageSpecificAnalyzeSyntax(SyntaxNodeAnalysisContext context, SyntaxTree syntaxTree, OptionSet optionSet) |
| nameof(PreferInferredTupleNames), | ||
| defaultValue: TrueWithSuggestionEnforcement, | ||
| storageLocations: new OptionStorageLocation[] { | ||
| EditorConfigStorageLocation.ForBoolCodeStyleOption("dotnet_style_prefer_inferred_tuple_names"), |
There was a problem hiding this comment.
Might be worth calling out somewhere this is an explicit back compat break.
There was a problem hiding this comment.
@jinujoseph @kuhlenh Is there a place to document code compat breaks in code style options?
There was a problem hiding this comment.
I can add a note to the documentation that it used to be separate but now it is not (and that the previous options are not supported). I never documented the previous version, so we should be ok...
| Select Case node.Kind | ||
| Case SyntaxKind.NameColonEquals | ||
| editor.RemoveNode(node, SyntaxRemoveOptions.KeepExteriorTrivia Or SyntaxRemoveOptions.AddElasticMarker) | ||
| Exit Select |
There was a problem hiding this comment.
@jasonmalinowski I didn't understand the question
There was a problem hiding this comment.
You don't need to Exit Select at the end of a case. This isn't C.
There was a problem hiding this comment.
(Exit Select in VB is not mandatory)
| var cancellationToken = context.CancellationToken; | ||
|
|
||
| var syntaxTree = context.Node.SyntaxTree; | ||
| var optionSet = context.Options.GetDocumentOptionSetAsync(syntaxTree, cancellationToken).GetAwaiter().GetResult(); |
There was a problem hiding this comment.
One thing @sharwell recently noticed: this isn't exactly a cheap call, and it's quite wasteful if you're not going to be on a node that you can fix -- i.e. checking kind first is often a better idea. I'll let him speak to whether he's seen this one pop and it's worth fixing now, or not.
There was a problem hiding this comment.
@sharwell Any thoughts on Jason's perf question?
There was a problem hiding this comment.
➡️ No need to fix it as part of this pull request. The new form is equivalent to the old form, so if it matters it's going to be showing up separately anyway.
|
|
||
| var syntaxTree = context.Node.SyntaxTree; | ||
| var optionSet = context.Options.GetDocumentOptionSetAsync(syntaxTree, cancellationToken).GetAwaiter().GetResult(); | ||
| if (optionSet == null) |
There was a problem hiding this comment.
I know you're preserving existing code, but this can't happen.
|
As long as we are OK not handing back compat I am fine with this. |
|
@Pilchie for ask-mode approval for 15.6. Details up top. Thanks |
* dotnet/master: (39 commits) Prefer by-val methods over in methods in overload resolution (dotnet#23122) Update build to account for additional Mono.Cecil assemblies Fix build break Enable multicore JIT in the compilers (dotnet#23173) Separate debugging workspace service and EnC service (dotnet#23630) UseInferredMemberName: use one code style option and share more code (dotnet#23506) Add negative test cases Remove unnecessary Mono.Cecil reference Updated formatting of decompiler license notice Use sentence case for the decompiler legal notice Use ConcurrentDictionary to avoid locks in IsGeneratedCode and HasHiddenRegions Recognize condition with logical negation Refactor so that GetSymbolInfo can be called last Change the code fix to find the expression so that we don't need to unwrap the argument Add check for null argument syntax Fix argument names Formatting adjustments Add VB tests for omitted arguments Add WorkItem attributes Pool the Stopwatch instance used in the analyzer driver ...
|
@kuhlenh Should we document the new/merged option? |
|
Ping @kuhlenh. This fix was merged to 15.6 and can be documented. Thanks |
|
@jcouv -- Beautiful! Will get it documented ASAP. Thank you! |
Customer scenario
We used to expose language-specific code style options for inferred member names:
With this PR, we now use fewer options, which can still be used to achieve the same effect:
I also noticed that the analyzers and code fixers for those options share a lot of code between C# and VB, so I pulled that code into base classes.
Bugs this fixes
#23313
Risk
Low. The change is limited to one analyzer+code fixer.
Performance impact
None. No added complexity or logic.
Is this a regression from a previous update?
No.
How was the bug found?
Reported by Kasey as she was documenting the code fixers.