-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
add the first set of editor options for visual studio #15020
add the first set of editor options for visual studio #15020
Conversation
using Microsoft.CodeAnalysis.Options; | ||
using System.Linq; |
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.
Sort usings. #Pending
|
||
public static Option<bool> SpaceWithinMethodDeclarationParenthesis { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceWithinMethodDeclarationParenthesis), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceWithinMethodDeclarationParenthesis")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_within_method_declaration_parameter_list_parenthesis"), |
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.
within the parentheses (plural)? #Pending
|
||
public static Option<bool> SpaceWithinMethodCallParentheses { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceWithinMethodCallParentheses), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceWithinMethodCallParentheses")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_within_method_call_parameter_list_parenthesis"), |
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.
Same as above. Parentheses (plural)? #Pending
|
||
public static Option<bool> SpaceWithinExpressionParentheses { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceWithinExpressionParentheses), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceWithinExpressionParentheses")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_within_parentheses", (s) => ParseSpaceOptions(s, SpacingOption.Expressions)), |
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.
there's a zillion other csharp_space_within_*_parentheses
, so this one without the *
is confusing to me. Maybe csharp_space_within_expression_parentheses
? #Resolved
|
||
public static Option<bool> SpaceWithinCastParentheses { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceWithinCastParentheses), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceWithinCastParentheses")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_within_parentheses", (s) => ParseSpaceOptions(s, SpacingOption.TypeCasts)), |
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.
Oh, this is why. You collapsed several of these into one... Ugh. csharp_space_within_other_parentheses
? I don't love it, but I don't love the unqualified version more. #ByDesign
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.
(Feel free to disagree) #ByDesign
|
||
public static Option<bool> SpacesIgnoreAroundVariableDeclaration { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpacesIgnoreAroundVariableDeclaration), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpacesIgnoreAroundVariableDeclaration")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_in_declaration_statements"), |
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.
One of these says "spacesignore" and the other one says "space_in" -- is this backwards? #Resolved
|
||
public static Option<bool> SpaceAfterColonInBaseTypeDeclaration { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceAfterColonInBaseTypeDeclaration), defaultValue: true, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceAfterColonInBaseTypeDeclaration")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_after_colon_for_base_or_interface_in_type_declaration"), |
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.
Can we do better with the name? I'm not sure how, but maybe there's a way. #Resolved
|
||
public static Option<bool> IndentSwitchSection { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(IndentSwitchSection), defaultValue: true, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.IndentSwitchSection")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_indent_case_labels"), |
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.
it also indents default:
which is probably why they call it "SwitchSection" in the option name. Not sure I care, though. #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.
And you matched the text in Tools | Options. It's fine. #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.
"indent_switch_labels"
|
||
public static Option<bool> WrappingPreserveSingleLine { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(WrappingPreserveSingleLine), defaultValue: true, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.WrappingPreserveSingleLine")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_wrap_block_on_single_line"), |
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.
For "spacing" and "indent" the names read nicely. csharp_space_goes_wherever
and indent_some_construct
. With wrap
it doesn't parse so cleanly for me. This makes it seem like you're trying to wrap a block on a single line. I understand that it should be parsed csharp_wrap
(pause) block_on_single_line
but it's hard to read it that way. #ByDesign
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 is a tradeoff between understandable structure and English readability. I don't think I'll change this as I csharp_wrap
gives structure to these set of options
In reply to: 87113514 [](ancestors = 87113514)
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.
csharp_wrapping_preserve_block_on_single_line?
csharp_wrapping_keep_block_on_single_line?
csharp_wrapping_do_not_wrap_single_line_block? (my preference)
csharp_wrapping_preserve_single_line_block?
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.
I do not think I will use wrapping as no other option uses that tense.
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.
So, "csharp_wrap_block_on_single_line = true" means "do not wrap a block on a single line? That's super8 confusing.
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.
we need something to indicate that when these are set to true, we do not wrap.
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.
|
||
public static Option<bool> NewLineForMembersInAnonymousTypes { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(NewLineForMembersInAnonymousTypes), defaultValue: true, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.NewLineForMembersInAnonymousTypes")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_new_line_before_members_in_anonymouse_types"), |
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.
csharp_new_line_before_members_in_anonymouse_types
incorrect spelling of anonymous #Resolved
6b1fabe
to
c20c007
Compare
{ | ||
public static partial class CSharpFormattingOptions | ||
{ | ||
internal static bool ParseParenthesesSpaceOptions(string value, SpacingWithinParenthesesOption parenthesesSpacingOption) |
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.
Strange function signature. It's called 'ParseXXX' but returns a bool?
switch (binaryOperatorSpacingValue) | ||
{ | ||
case "ignore": return BinaryOperatorSpacingOptions.Ignore; | ||
case "none": return BinaryOperatorSpacingOptions.Remove; |
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.
it bothers me that tehse names don't match.
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.
I'm preferring the names we expose in the IDE over the variable names. It would be a breaking API change the modify the enum names as BinaryOperatorSpacingOptions
is a public type.
|
||
internal static bool ParseNewLineOption(string value, NewLineOption optionName) | ||
{ | ||
var values = value.Split(',').Select((v) => v.Trim()); |
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.
parens around (v) not needed
{ | ||
var values = value.Split(',').Select((v) => v.Trim()); | ||
|
||
if (values.Any((v) => v == "all")) |
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.
same.
|
||
public static Option<bool> SpaceBetweenEmptyMethodCallParentheses { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceBetweenEmptyMethodCallParentheses), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceBetweenEmptyMethodCallParentheses")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_within_method_call_empty_parameter_list_parentheses"), |
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.
i'm torn on how i feel about this. So Roslyn calls these 'Invocations' not method-calls. But the old IDE called the method calls. I'm wondering if we should unify on roslyn naming as we move forward. A core reason for this is that we often have confusion around what the option name is and what it actually controls with our new APi.
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.
I think calls is fine - it's throughout the IDE (Call Hierachy, Call stack, etc). I see no reason to change the user facing term to the API term.
[InlineData("type_casts, expressions, , ", SpacingWithinParenthesesOption.TypeCasts)] | ||
[InlineData("expressions , , , control_flow_statements", SpacingWithinParenthesesOption.ControlFlowStatements)] | ||
[InlineData("expressions , , , control_flow_statements", SpacingWithinParenthesesOption.Expressions)] | ||
[InlineData(", , , control_flow_statements", SpacingWithinParenthesesOption.ControlFlowStatements)] |
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.
witchcraft!
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.
Alternatively, get rid of a bunch of brackets and just put ,
between the atrributes
c20c007
to
2654a6c
Compare
We can deprecate the old names, and add the new names to the enum, with the same values as the older ones. |
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.
So excited to have this.
Should we re-base to dev15-rc2
?
|
||
public static Option<bool> SpaceBetweenEmptyMethodCallParentheses { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceBetweenEmptyMethodCallParentheses), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceBetweenEmptyMethodCallParentheses")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_within_method_call_empty_parameter_list_parentheses"), |
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.
I think calls is fine - it's throughout the IDE (Call Hierachy, Call stack, etc). I see no reason to change the user facing term to the API term.
{ | ||
public static Option<bool> SpacingAfterMethodDeclarationName { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpacingAfterMethodDeclarationName), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpacingAfterMethodDeclarationName")); | ||
storageLocations: new OptionStorageLocation[] { |
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.
Nit: Can you use implicit array creations here with just new [] {...
?
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.
EditorConfigStorageLocation
and RoamingProfileStorageLocation
are both derived from OptionStorageLocation
but implicit array creation cannot infer OptionStorageLocation
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.
That seems unexpected/crappy. :-/
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.
I could cast them explcitly
public static Option<bool> SpaceWithinMethodDeclarationParenthesis { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpaceWithinMethodDeclarationParenthesis), defaultValue: false,
storageLocations: new [] {
(OptionStorageLocation)new EditorConfigStorageLocation("csharp_space_within_method_declaration_parameter_list_parentheses"),
(OptionStorageLocation)new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpaceWithinMethodDeclarationParenthesis")});
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.
No, this is fine if it's the best the compiler can do.
[InlineData("type_casts, expressions, , ", SpacingWithinParenthesesOption.TypeCasts)] | ||
[InlineData("expressions , , , control_flow_statements", SpacingWithinParenthesesOption.ControlFlowStatements)] | ||
[InlineData("expressions , , , control_flow_statements", SpacingWithinParenthesesOption.Expressions)] | ||
[InlineData(", , , control_flow_statements", SpacingWithinParenthesesOption.ControlFlowStatements)] |
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.
Alternatively, get rid of a bunch of brackets and just put ,
between the atrributes
2654a6c
to
3f8fc56
Compare
3f8fc56
to
4769c05
Compare
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.
Nitpicks only.
{ | ||
public static partial class CSharpFormattingOptions | ||
{ | ||
internal static bool DetermindIfSpaceOptionIsSet(string value, SpacingWithinParenthesesOption parenthesesSpacingOption) |
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.
Typo: "Determind".
{ | ||
internal static bool DetermindIfSpaceOptionIsSet(string value, SpacingWithinParenthesesOption parenthesesSpacingOption) | ||
=> (from v in value.Split(',').Select(v => v.Trim()) | ||
let option = ConvertToSpacingOption(v) |
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.
You could just select ConvertToSpacingOption directly and the .Any() would just handle the null case for you, right?
} | ||
} | ||
|
||
internal static object ParseEditorConfigSpacingAroundBinaryOperator(string binaryOperatorSpacingValue) |
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.
Why weakly typed here?
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.
EditorConfigStorageLocation
requires Func<string, object>
Error CS0407 'BinaryOperatorSpacingOptions CSharpFormattingOptions.ParseEditorConfigSpacingAroundBinaryOperator(string)' has the wrong return 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.
I'd prefer the return type still be: "BinaryOperatorSpacingOptions ". But htat hte consumer does hte conversion with a lambda.
} | ||
} | ||
|
||
internal static object ParseEditorConfigLabelPositioning(string lableIndentationValue) |
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.
Typo: "lable"
{ | ||
var values = value.Split(',').Select(v => v.Trim()); | ||
|
||
if (values.Any(v => v == "all")) |
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.
.Contains?
} | ||
|
||
return (from v in values | ||
let option = ConvertToNewLineOption(v) |
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.
Can we unify this code with the other Determine* functions?
{ | ||
public static Option<bool> SpacingAfterMethodDeclarationName { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpacingAfterMethodDeclarationName), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpacingAfterMethodDeclarationName")); | ||
storageLocations: new OptionStorageLocation[] { |
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.
That seems unexpected/crappy. :-/
|
||
public static Option<bool> SpacesIgnoreAroundVariableDeclaration { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpacesIgnoreAroundVariableDeclaration), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpacesIgnoreAroundVariableDeclaration")); | ||
storageLocations: new OptionStorageLocation[] { | ||
new EditorConfigStorageLocation("csharp_space_ignore_around_declaration_statements"), |
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.
Is this one better done as csharp_space_around_declaration_statements = ignore or something? It feels like having the checkboxes that say "don't do this".
[InlineData("one_less_than_current", LabelPositionOptions.OneLess)] | ||
static void TestParseEditorConfigLabelPositioningTrue(string value, LabelPositionOptions expectedValue) | ||
{ | ||
Assert.True((LabelPositionOptions)ParseEditorConfigLabelPositioning(value) == expectedValue, |
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.
Yep, let's make these methods more strongly typed.
@Pilchie @MattGertz @natidea I've re-targeted the PR against RC.2, please let me know it we want to take this. Customer scenario
Bugs this fixes: (either VSO or GitHub links)Workarounds
Risk
Performance impact
Is this a regression from a previous update?
Root cause analysis: how did we miss it? What tests are we adding to guard against it in the future?
How was the bug found? (E.g. customer reported it vs. ad hoc testing)
|
We certainly can. I would need to compat council to sign off in that case |
Approved pending @dpoeschl agreement re:his requested changes. |
{ | ||
public static Option<bool> SpacingAfterMethodDeclarationName { get; } = new Option<bool>(nameof(CSharpFormattingOptions), nameof(SpacingAfterMethodDeclarationName), defaultValue: false, | ||
storageLocations: new RoamingProfileStorageLocation("TextEditor.CSharp.Specific.SpacingAfterMethodDeclarationName")); | ||
storageLocations: new OptionStorageLocation[] { |
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.
No, this is fine if it's the best the compiler can do.
33fc8a6
to
4c9163f
Compare
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 all the changes. Looking good.
csharp_space_after_colon_for_base_or_interface_in_type_declaration => csharp_space_after_colon_in_inheritance_clause |
csharp_space_between_method_declaration_name_and_open_parentheses => csharp_space_between_method_declaration_name_and_open_parenthesis csharp_space_around_operators => csharp_space_around_binary_operators ? csharp_keep_block_on_single_line => csharp_preserve_single_line_blocks csharp_preserve_single_line_member_declarations |
not suggesitng, just preserving: also: mouse. |
6ab5f8e
to
d46a349
Compare
@CyrusNajmabadi Updated with your suggestions for |
csharp_new_line_before_open_brace Spacing Options Usages of both between and within. Seems synonymous. What happened to csharp_preserve_single_line_member_declarations? |
Options updated
Done
Use within everywhere
I don't know, I've never used that as a name for anything and I can't remember why you wrote it in the previous comment. Do you recall what this was about? |
Is this about the space in a field/location declaration? Or does it refer to more than that? |
Overall i like it. I feel like i like "between" versus "within". I think it reads better. But if you feel "within" is better, i'll defer. |
It should just be about field /local declarations. I've updated the possible values to be more clear
I only picked |
👍 |
1a3dd29
to
c0cd291
Compare
How is |
You can specify If var x = 3;
var y = 4;
var z = ( x * y ) - ( ( y - x ) * 3 ); If var x = 3;
var y = 4;
var z = (x * y) - ((y - x) * 3); If int y = ( int )x; If int y = (int)x; If for( int i; i < x; i++ )
{
} If for(int i; i < x; i++)
{
} An example of all three specified in an editorconfig file would be:
|
I didn't know multiple values were allowed, this isn't obvious. What's the value for none of these? Simply |
@ygoe do not specify the option at all if you do not want spaces added in any of these scenarios. |
Some of these options may be removed at some point due to low to no useage, which is why we haven't documented several of them. Is this an option that you want to turn on? |
My point is to explicitly override whatever the IDE is configured to. Not specifying the option means "no intent" which is different from "intent to not use spaces". All other options let me specify "true", "false" or nothing at all. This one is different. |
@dotnet/roslyn-ide @jasonmalinowski
Adds the following options
Advanced
Indentation Options
New Line Options
Spacing Options
Wrapping Options