Skip to content

Commit

Permalink
Add alignWithFirstAttr option to xml.format.splitAttributes
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica He <jhe@redhat.com>
  • Loading branch information
JessicaJHee authored and datho7561 committed Jul 26, 2023
1 parent e5baa16 commit 82ca5d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
29 changes: 22 additions & 7 deletions docs/Formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ No changes to quotes will occur during formatting if `xml.format.enforceQuoteSty

### xml.format.preserveAttributeLineBreaks

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`.
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`.

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

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

### xml.format.splitAttributes

Set to `true` to split node attributes onto multiple lines during formatting. Defaults to `false`.
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.

Available values are `preserve`, `splitNewLine`, and `alignWithFirstAttr`. Defaults to `preserve`.

Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](#xmlformatpreserveattributelinebreaks).
Please see [xml.format.splitAttributesIndentSize](#xmlformatsplitAttributesIndentSize) for information on configuring the indentation level of the attributes.

Please see [xml.format.splitAttributesIndentSize](#xmlformatsplitAttributesIndentSize) for information on configuring the indentation level of the attributes in the case of `splitNewLine`.

The following xml:
```xml
<project a="1" b="2" c="3"></project>
```
becomes...

Remains the same when set to `preserve`.

When set to `splitNewLine`, becomes:
```xml
<project
a="1"
b="2"
c="3"></project>
```

When set to `alignWithFirstAttr`, becomes:
```xml
<project a="1"
b="2"
c="3"></project>
```

***

### xml.format.joinCDATALines
Expand Down Expand Up @@ -453,7 +468,7 @@ If `xml.format.joinContentLines` is set to `true`, the above document becomes:
weight='20' />
</ROOT:root>
```
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.
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.

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

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

### xml.format.splitAttributesIndentSize

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

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

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

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

Requires [splitAttributes](#xmlformatsplitattributes) to be set to `true`.
Requires [splitAttributes](#xmlformatsplitattributes) to be set to `splitNewLine` or `alignWithFirstAttr`.

Defaults to `false`.

Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
"xml.format.preserveAttributeLineBreaks": {
"type": "boolean",
"default": true,
"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.",
"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.",
"scope": "window"
},
"xml.format.preserveEmptyContent": {
Expand Down Expand Up @@ -404,9 +404,14 @@
"scope": "window"
},
"xml.format.splitAttributes": {
"type": "boolean",
"default": false,
"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.",
"type": "string",
"enum": [
"preserve",
"splitNewLine",
"alignWithFirstAttr"
],
"default": "preserve",
"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.",
"scope": "window"
},
"xml.format.splitAttributesIndentSize": {
Expand Down
2 changes: 1 addition & 1 deletion src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export function getXMLSettings(javaHome: string | undefined, logfile: string, ex
},
format: {
enabled: true,
splitAttributes: false
splitAttributes: 'preserve'
},
completion: {
autoCloseTags: false
Expand Down

0 comments on commit 82ca5d3

Please sign in to comment.