Skip to content

Commit 82ca5d3

Browse files
JessicaJHeedatho7561
authored andcommitted
Add alignWithFirstAttr option to xml.format.splitAttributes
Signed-off-by: Jessica He <[email protected]>
1 parent e5baa16 commit 82ca5d3

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

docs/Formatting.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ No changes to quotes will occur during formatting if `xml.format.enforceQuoteSty
155155

156156
### xml.format.preserveAttributeLineBreaks
157157

158-
Preserve line breaks that appear before and after attributes. This setting is overridden if [xml.format.splitAttributes](#xmlformatsplitattributes) is set to `true`. Default is `true`.
158+
Preserve line breaks that appear before and after attributes. This setting is overridden if [xml.format.splitAttributes](#xmlformatsplitattributes) is set to `splitNewLine` or `alignWithFirstAttr`. Default is `true`.
159159

160160
If set to `true`, formatting does not change the following document:
161161

@@ -241,21 +241,36 @@ If this value is set to 0, then all blank lines will be removed during formattin
241241

242242
### xml.format.splitAttributes
243243

244-
Set to `true` to split node attributes onto multiple lines during formatting. Defaults to `false`.
244+
Set to `splitNewLine` to split node attributes onto multiple lines during formatting and set to `alignWithFirstAttr` to split node attributes after the first attribute to align with it.
245+
246+
Available values are `preserve`, `splitNewLine`, and `alignWithFirstAttr`. Defaults to `preserve`.
247+
245248
Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](#xmlformatpreserveattributelinebreaks).
246-
Please see [xml.format.splitAttributesIndentSize](#xmlformatsplitAttributesIndentSize) for information on configuring the indentation level of the attributes.
247249

250+
Please see [xml.format.splitAttributesIndentSize](#xmlformatsplitAttributesIndentSize) for information on configuring the indentation level of the attributes in the case of `splitNewLine`.
251+
252+
The following xml:
248253
```xml
249254
<project a="1" b="2" c="3"></project>
250255
```
251-
becomes...
256+
257+
Remains the same when set to `preserve`.
258+
259+
When set to `splitNewLine`, becomes:
252260
```xml
253261
<project
254262
a="1"
255263
b="2"
256264
c="3"></project>
257265
```
258266

267+
When set to `alignWithFirstAttr`, becomes:
268+
```xml
269+
<project a="1"
270+
b="2"
271+
c="3"></project>
272+
```
273+
259274
***
260275

261276
### xml.format.joinCDATALines
@@ -453,7 +468,7 @@ If `xml.format.joinContentLines` is set to `true`, the above document becomes:
453468
weight='20' />
454469
</ROOT:root>
455470
```
456-
Note that it references two different external schemas. Additionally, the setting [`xml.format.splitAttributes`](#xmlformatsplitattributes) will be set to true for the formatted examples in order to make the formatted result easier to see.
471+
Note that it references two different external schemas. Additionally, the setting [`xml.format.splitAttributes`](#xmlformatsplitattributes) will be set to `splitNewLine` for the formatted examples in order to make the formatted result easier to see.
457472

458473
* When it is set to `none`, the formatter does not change the content of `xsi:schemaLocation`. The above file would not change after formatting.
459474

@@ -491,7 +506,7 @@ If `xml.format.joinContentLines` is set to `true`, the above document becomes:
491506

492507
### xml.format.splitAttributesIndentSize
493508

494-
Use to configure how many levels to indent the attributes by when [xml.format.splitAttributes](#xmlformatsplitAttributes) is set to `true`.
509+
Use to configure how many levels to indent the attributes by when [xml.format.splitAttributes](#xmlformatsplitAttributes) is set to `splitNewLine`.
495510

496511
Here are some examples. For these examples, an indentation is two spaces.
497512

@@ -559,7 +574,7 @@ If set to `true`, the closing bracket (`>` or `/>`) of a tag with at least 2 att
559574

560575
The closing bracket will have the same indentation as the attributes (if any), following the indent level defined by [splitAttributesIndentSize](#xmlformatsplitattributesindentsize).
561576

562-
Requires [splitAttributes](#xmlformatsplitattributes) to be set to `true`.
577+
Requires [splitAttributes](#xmlformatsplitattributes) to be set to `splitNewLine` or `alignWithFirstAttr`.
563578

564579
Defaults to `false`.
565580

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
"xml.format.preserveAttributeLineBreaks": {
342342
"type": "boolean",
343343
"default": true,
344-
"markdownDescription": "Preserve line breaks that appear before and after attributes. This setting is overridden if `#xml.format.splitAttributes#` is set to `true`. Default is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatpreserveattributelinebreaks%22%7D%5D) for more information.",
344+
"markdownDescription": "Preserve line breaks that appear before and after attributes. This setting is overridden if `#xml.format.splitAttributes#` is set to `splitNewLine` or `alignWithFirstAttr`. Default is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatpreserveattributelinebreaks%22%7D%5D) for more information.",
345345
"scope": "window"
346346
},
347347
"xml.format.preserveEmptyContent": {
@@ -404,9 +404,14 @@
404404
"scope": "window"
405405
},
406406
"xml.format.splitAttributes": {
407-
"type": "boolean",
408-
"default": false,
409-
"markdownDescription": "Split multiple attributes each onto a new line. Default is `false`. Indicate level of indentation with `#xml.format.splitAttributesIndentSize#`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatsplitattributes%22%7D%5D) for more information.",
407+
"type": "string",
408+
"enum": [
409+
"preserve",
410+
"splitNewLine",
411+
"alignWithFirstAttr"
412+
],
413+
"default": "preserve",
414+
"markdownDescription": "Split multiple attributes each onto a new line or align attributes to the first. Default is `preserve`. Indicate level of indentation with `#xml.format.splitAttributesIndentSize#`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatsplitattributes%22%7D%5D) for more information.",
410415
"scope": "window"
411416
},
412417
"xml.format.splitAttributesIndentSize": {

src/settings/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function getXMLSettings(javaHome: string | undefined, logfile: string, ex
203203
},
204204
format: {
205205
enabled: true,
206-
splitAttributes: false
206+
splitAttributes: 'preserve'
207207
},
208208
completion: {
209209
autoCloseTags: false

0 commit comments

Comments
 (0)