Add new option to control attribute indent style#12625
Add new option to control attribute indent style#12625davidwengier merged 5 commits intodev/dawengie/LetsDoHtmlFormattingfrom
Conversation
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Settings/AttributeIndentStyle.cs
Show resolved
Hide resolved
| <value>Align with first attribute</value> | ||
| </data> | ||
| <data name="Setting_AttributeIndentStyleIndentByOne" xml:space="preserve"> | ||
| <value>Indent by one level</value> |
There was a problem hiding this comment.
Added docs to the enum, its one level more indentation than the line that the start tag is on.
src/Razor/src/Microsoft.VisualStudio.RazorExtension/UnifiedSettings/razor.registration.json
Outdated
Show resolved
Hide resolved
| // We need to line up with the first attribute, but the start tag might not be the first thing on the line, | ||
| // so it's really relative to the first non-whitespace character on the line | ||
| var lineStart = _sourceText.Lines[GetLineNumber(startTag)].GetFirstNonWhitespacePosition().GetValueOrDefault(); | ||
| htmlIndentLevel = FormattingUtilities.GetIndentationLevel(nameSpan.Start - lineStart, _tabSize, out additionalIndentation); |
There was a problem hiding this comment.
The Html formatter always puts the first attribute on the same line as the start tag. Will add a test.
There was a problem hiding this comment.
Are you certain? In vscode, if I create a tag that starts at column 100 or so, it's first attribute is placed on the subsequent line. I thought the html formatter in VS did something similar at some point.
There was a problem hiding this comment.
Oh interesting, I was only testing at column 0. Thank you! Will add a test and make sure nothing bad happens.
There was a problem hiding this comment.
Updated the test I added in the other PR, to cover both indent styles
| "AutoInsertAttributeQuotes": false, | ||
| "CommitElementsWithSpace": false | ||
| "CommitElementsWithSpace": false, | ||
| "AttributeIndentStyle": 1 |
| using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; | ||
| using Microsoft.CodeAnalysis.Razor.Formatting; | ||
| using Microsoft.CodeAnalysis.Razor.Protocol; | ||
| using Microsoft.CodeAnalysis.Razor.Settings; |
There was a problem hiding this comment.
Was there a change that made this necessary?
There was a problem hiding this comment.
The AttributeIndentStyle reference on line 847
There was a problem hiding this comment.
I totally missed that change. The contrast in codeflow between the background and changed lines is evidently a bit tricky for my eyes. Switching to dark theme and it's a lot more evident now.
…ing' into dev/dawengie/HtmlAttributeIndentOption # Conflicts: # src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/CSharpFormattingPass.CSharpDocumentGenerator.cs
Fixes #6551
Fixes #8413
Adding an option is way too annoying! We'll have to fix that up when we get rid of the language server.