Skip to content

Formatting options refactoring - step 3#58904

Merged
tmat merged 3 commits into
dotnet:mainfrom
tmat:Formatter3
Jan 26, 2022
Merged

Formatting options refactoring - step 3#58904
tmat merged 3 commits into
dotnet:mainfrom
tmat:Formatter3

Conversation

@tmat
Copy link
Copy Markdown
Member

@tmat tmat commented Jan 17, 2022

Add fields for formatting options.

@tmat tmat changed the title Formatter3 Formatting options refactoring - step 3 Jan 18, 2022
@tmat tmat marked this pull request as ready for review January 18, 2022 18:42
@tmat tmat requested review from a team as code owners January 18, 2022 18:42
@tmat
Copy link
Copy Markdown
Member Author

tmat commented Jan 18, 2022

@CyrusNajmabadi PTAL

[Flags]
internal enum SpacePlacement
{
IgnoreAroundVariableDeclaration = 1,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
IgnoreAroundVariableDeclaration = 1,
IgnoreAroundVariableDeclaration = 1 << 0,

up to you :) i like the symettry.

bool useTabs,
int tabSize,
int indentationSize,
string newLine,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i feel like teh above 4 often go hand in hand. any thoughts on combining to a basic formatting options struct?

(options.GetOption(CSharpFormattingOptions2.NewLinesForBracesInAnonymousMethods) ? NewLinePlacement.BeforeOpenBraceInAnonymousMethods : 0) |
(options.GetOption(CSharpFormattingOptions2.NewLinesForBracesInLambdaExpressionBody) ? NewLinePlacement.BeforeOpenBraceInLambdaExpressionBody : 0) |
(options.GetOption(CSharpFormattingOptions2.NewLinesForBracesInControlBlocks) ? NewLinePlacement.BeforeOpenBraceInControlBlocks : 0) |
(options.GetOption(CSharpFormattingOptions2.NewLineForClausesInQuery) ? NewLinePlacement.BetweenQueryExpressionClauses : 0),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't love the difference in names here. any thought on unification?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I named the flags based on the editorconfig names. I can follow up to rename the options as well. Tracking: #59089

public override AbstractFormattingRule WithOptions(SyntaxFormattingOptions options)
{
var cachedOptions = new CachedOptions(options.Options);
var newOptions = options as CSharpSyntaxFormattingOptions ?? CSharpSyntaxFormattingOptions.Default;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yick. should we throw if we ere not given a CSharpSyntaxFormattingOptions ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure how this may be used right now. I was being conservative here and preserve the behavior.

public override AbstractFormattingRule WithOptions(SyntaxFormattingOptions options)
{
var cachedOptions = new CachedOptions(options.Options);
var newOptions = options as CSharpSyntaxFormattingOptions ?? CSharpSyntaxFormattingOptions.Default;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same yick.

public readonly bool UseTabs;
public readonly int TabSize;
public readonly int IndentationSize;
public readonly string NewLine;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'd actually love for these four to be their own struct.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Possibly. We can do another round of refactorings/renames once finished with all options.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@tmat tmat merged commit e1cfa48 into dotnet:main Jan 26, 2022
@ghost ghost added this to the Next milestone Jan 26, 2022
@tmat tmat deleted the Formatter3 branch January 26, 2022 23:32
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P1 Feb 4, 2022
@ryzngard ryzngard added UX Review Not Required UX Review Not Required and removed Needs UX Triage labels Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants