Skip to content

UseInferredMemberName: use one code style option and share more code#23506

Merged
jcouv merged 2 commits intodotnet:masterfrom
jcouv:ide-options
Dec 8, 2017
Merged

UseInferredMemberName: use one code style option and share more code#23506
jcouv merged 2 commits intodotnet:masterfrom
jcouv:ide-options

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Nov 30, 2017

Customer scenario

We used to expose language-specific code style options for inferred member names:

csharp_prefer_inferred_tuple_names = true:suggestion 
csharp_prefer_inferred_anonymous_type_member_names = true:suggestion 
visual_basic_prefer_inferred_tuple_names = true:suggestion 
visual_basic_prefer_inferred_anonymous_type_member_names = true:suggestion

With this PR, we now use fewer options, which can still be used to achieve the same effect:

[*.cs]
dotnet_style_prefer_inferred_tuple_names = true:suggestion 
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 

[*.vb]
dotnet_style_prefer_inferred_tuple_names = true:suggestion 
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 

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.

@jcouv jcouv added the Area-IDE label Nov 30, 2017
@jcouv jcouv added this to the 15.6 milestone Nov 30, 2017
@jcouv jcouv self-assigned this Nov 30, 2017
@jcouv jcouv requested a review from a team as a code owner November 30, 2017 23:24
=> context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.NameColon, SyntaxKind.NameEquals);

private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
override protected void LanguageSpecificAnalyzeSyntax(SyntaxNodeAnalysisContext context, SyntaxTree syntaxTree, OptionSet optionSet)
Copy link
Member

Choose a reason for hiding this comment

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

protected override

nameof(PreferInferredTupleNames),
defaultValue: TrueWithSuggestionEnforcement,
storageLocations: new OptionStorageLocation[] {
EditorConfigStorageLocation.ForBoolCodeStyleOption("dotnet_style_prefer_inferred_tuple_names"),
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth calling out somewhere this is an explicit back compat break.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jinujoseph @kuhlenh Is there a place to document code compat breaks in code style options?

Copy link

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

This is implied...?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasonmalinowski I didn't understand the question

Copy link
Member

Choose a reason for hiding this comment

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

You don't need to Exit Select at the end of a case. This isn't C.

Copy link
Member

Choose a reason for hiding this comment

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

(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();
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sharwell Any thoughts on Jason's perf question?

Copy link
Contributor

Choose a reason for hiding this comment

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

➡️ 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)
Copy link
Member

Choose a reason for hiding this comment

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

I know you're preserving existing code, but this can't happen.

Copy link
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

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

:shipit:

@jmarolf
Copy link
Contributor

jmarolf commented Dec 1, 2017

As long as we are OK not handing back compat I am fine with this.

@jcouv
Copy link
Member Author

jcouv commented Dec 8, 2017

@Pilchie for ask-mode approval for 15.6. Details up top. Thanks

@jcouv jcouv merged commit de637d5 into dotnet:master Dec 8, 2017
@jcouv jcouv deleted the ide-options branch December 8, 2017 16:43
333fred added a commit to 333fred/roslyn that referenced this pull request Dec 9, 2017
* 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
  ...
@jcouv
Copy link
Member Author

jcouv commented Dec 30, 2017

@kuhlenh Should we document the new/merged option?

@jcouv
Copy link
Member Author

jcouv commented Jan 4, 2018

Ping @kuhlenh. This fix was merged to 15.6 and can be documented. Thanks

@kuhlenh
Copy link

kuhlenh commented Jan 5, 2018

@jcouv -- Beautiful! Will get it documented ASAP. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants