From 0aa5422a16ebed983b3a4bbbc4c0cc4ed5624f93 Mon Sep 17 00:00:00 2001 From: Jessica He Date: Wed, 26 Jul 2023 12:46:06 -0400 Subject: [PATCH] Add alignWithFirstAttr option to xml.format.splitAttributes Signed-off-by: Jessica He --- docs/Formatting.md | 29 ++++++++++++++++++++++------- package.json | 13 +++++++++---- src/settings/settings.ts | 2 +- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/docs/Formatting.md b/docs/Formatting.md index 3fa467dd..9eadabc2 100644 --- a/docs/Formatting.md +++ b/docs/Formatting.md @@ -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: @@ -241,14 +241,22 @@ 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 ``` - becomes... + + Remains the same when set to `preserve`. + + When set to `splitNewLine`, becomes: ```xml ``` + When set to `alignWithFirstAttr`, becomes: + ```xml + + ``` + *** ### xml.format.joinCDATALines @@ -453,7 +468,7 @@ If `xml.format.joinContentLines` is set to `true`, the above document becomes: weight='20' /> ``` - 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. @@ -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. @@ -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`. diff --git a/package.json b/package.json index 51945493..2890d8a5 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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": { diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 1a3846cc..f9988f86 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -203,7 +203,7 @@ export function getXMLSettings(javaHome: string | undefined, logfile: string, ex }, format: { enabled: true, - splitAttributes: false + splitAttributes: 'preserve' }, completion: { autoCloseTags: false