Skip to content

Commit f646d17

Browse files
committed
Add new formatting setting xml.format.splitAttributesIndentSize
Add a new setting which controls the level of indentation of attributes with respect to their parent element when `xml.format.splitAttributes` is set to `true`. Based off of a comment by Cong Wang (@I322871) on the vscode-xml Gitter Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 20f8e75 commit f646d17

File tree

4 files changed

+102
-33
lines changed

4 files changed

+102
-33
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ This VS Code extension provides support for creating and editing XML documents,
3232
* Code actions
3333
* Schema Caching
3434

35-
See the [changelog](CHANGELOG.md) for the latest release.
35+
See the [changelog](CHANGELOG.md) for the latest release.
3636

37-
You might also find useful information in the [Online XML Documentation](https://github.com/redhat-developer/vscode-xml/blob/master/docs/README.md)
37+
You might also find useful information in the [Online XML Documentation](https://github.com/redhat-developer/vscode-xml/blob/master/docs/README.md)
3838
or you can read this documentation inside vscode with the command `Open XML Document` available with `Ctrl+Shift+P`:
3939

4040
![XML Open Documentation](https://raw.githubusercontent.com/redhat-developer/vscode-xml/master/docs/images/Commands/XMLCommands.png)
@@ -46,7 +46,7 @@ or you can read this documentation inside vscode with the command `Open XML Docu
4646
* `xml.java.home` in VSCode preferences
4747
* `java.home` in VSCode preferences
4848
* Environment variable `JAVA_HOME` or `JDK_HOME`
49-
* **Note**: The path should end at the parent folder that contains the `bin` folder.
49+
* **Note**: The path should end at the parent folder that contains the `bin` folder.
5050
**Example Path**: `/usr/lib/jvm/java-1.8.0` if `bin` exists at `/usr/lib/jvm/java-1.8.0/bin`.
5151
* **Note**: If the path is not set, the extension will attempt to find the path to the JDK or JRE.
5252

@@ -57,7 +57,7 @@ See [how to set java home](https://github.com/redhat-developer/vscode-xml/blob/m
5757
The following settings are supported:
5858

5959
* [`xml.java.home`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#java-home): Set the Java path required to run the XML Language Server. If not set, falls back to either the `java.home` preference or the `JAVA_HOME` or `JDK_HOME` environment variables.
60-
* [`xml.server.vmargs`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#server-vm-arguments): Specifies extra VM arguments used to launch the XML Language Server.
60+
* [`xml.server.vmargs`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#server-vm-arguments): Specifies extra VM arguments used to launch the XML Language Server.
6161
Eg. use `-Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication` to bypass class verification, increase the heap size to 1GB and enable String deduplication with the G1 Garbage collector.
6262
* [`xml.server.workDir`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#server-cache-path): Set a custom folder path for cached XML Schemas. An absolute path is expected, although the `~` prefix (for the user home directory) is supported. Default is `~/.lemminx`.
6363
* `xml.trace.server`: Trace the communication between VS Code and the XML language server in the Output view. Default is `off`.
@@ -70,15 +70,16 @@ The following settings are supported:
7070
* [`xml.format.joinCDATALines`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatjoincdatalines): Set to `true` to join lines in CDATA content during formatting. Default is `false`.
7171
* [`xml.format.joinCommentLines`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatjoincommentlines): Set to `true` to join lines in comments during formatting. Default is `false`.
7272
* [`xml.format.joinContentLines`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatjoincontentlines): Normalize the whitespace of content inside an element. Newlines and excess whitespace are removed. Default is `false`.
73-
* [`xml.format.preserveAttributeLineBreaks`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatpreserveattributelinebreaks): Preserve line breaks that appear before and after attributes. Default is `false`.
73+
* [`xml.format.preserveAttributeLineBreaks`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatpreserveattributelinebreaks): Preserve line breaks that appear before and after attributes. Default is `false`.
7474
**IMPORTANT**: This setting is overridden if `xml.format.splitAttributes` is set to `true`.
7575
* [`xml.format.preserveEmptyContent`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatpreserveemptycontent): Preserve empty content/whitespace in a tag. Default is `false`.
7676
* [`xml.format.preservedNewLines`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatpreservednewlines): Preserve new lines that separate tags. The value represents the maximum number of new lines per section. A value of 0 removes all new lines. Default is `2`.
77-
* [`xml.format.spaceBeforeEmptyCloseTag`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatspacebeforeemptyclosetag): Insert space before end of self closing tag.
77+
* [`xml.format.spaceBeforeEmptyCloseTag`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatspacebeforeemptyclosetag): Insert space before end of self closing tag.
7878
Example: ```<tag/> -> <tag />```. Default is `true`.
7979
* [`xml.format.splitAttributes`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatsplitattributes): Split multiple attributes each onto a new line. Default is `false`.
80+
* [`xml.format.splitAttributesIndentSize`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatsplitattributesindentsize): How many levels to indent the attributes by when `xml.format.splitAttributes` is `true`. Default value is 2.
8081
* `xml.preferences.quoteStyle`: Preferred quote style to use for completion: `single` quotes, `double` quotes. Default is `double`.
81-
* `xml.autoCloseTags.enabled` : Enable/disable autoclosing of XML tags. Default is `true`.
82+
* `xml.autoCloseTags.enabled` : Enable/disable autoclosing of XML tags. Default is `true`.
8283
**IMPORTANT**: The following settings must be turned of for this to work: `editor.autoClosingTags`, `editor.autoClosingBrackets`.
8384
* [`xml.codeLens.enabled`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/CodeLens.md): Enable/disable XML CodeLens. Default is `false`.
8485
* [`xml.preferences.showSchemaDocumentationType`](https://github.com/redhat-developer/vscode-xml/blob/master/docs/Preferences.md#documentation-type): Specifies the source of the XML schema documentation displayed on hover and completion. Default is `all`.

docs/Formatting.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ If this value is set to 0, then all blank lines will be removed during formattin
148148
### xml.format.splitAttributes
149149

150150
Set to `true` to split node attributes onto multiple lines during formatting. Defaults to `false`.
151-
Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](#xmlformatpreserveattributelinebreaks)
151+
Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](#xmlformatpreserveattributelinebreaks).
152+
Please see [xml.format.splitAttributesIndentSize](#xmlformatsplitAttributesIndentSize) for information on configuring the indentation level of the attributes.
152153

153154
```xml
154155
<project a="1" b="2" c="3"></project>
@@ -332,4 +333,66 @@ If it is set to `true`, the above document becomes:
332333
```
333334

334335
***
336+
### xml.format.splitAttributesIndentSize
335337

338+
Use to configure how many levels to indent the attributes by when [xml.format.splitAttributes](#xmlformatsplitAttributes) is set to `true`.
339+
340+
Here are some examples. For these examples, an indentation is two spaces.
341+
342+
`xml.format.splitAttributesIndentSize = 2` (default)
343+
344+
```xml
345+
<robot attribute1="value1" attribute2="value2" attribute3="value3">
346+
<child />
347+
<child />
348+
</robot>
349+
```
350+
becomes
351+
```xml
352+
<robot
353+
attribute1="value1"
354+
attribute2="value2"
355+
attribute3="value3">
356+
<child />
357+
<child />
358+
</robot>
359+
```
360+
361+
`xml.format.splitAttributesIndentSize = 1`
362+
363+
```xml
364+
<robot attribute1="value1" attribute2="value2" attribute3="value3">
365+
<child />
366+
<child />
367+
</robot>
368+
```
369+
becomes
370+
```xml
371+
<robot
372+
attribute1="value1"
373+
attribute2="value2"
374+
attribute3="value3">
375+
<child />
376+
<child />
377+
</robot>
378+
```
379+
380+
`xml.format.splitAttributesIndentSize = 3`
381+
382+
```xml
383+
<robot attribute1="value1" attribute2="value2" attribute3="value3">
384+
<child />
385+
<child />
386+
</robot>
387+
```
388+
becomes
389+
```xml
390+
<robot
391+
attribute1="value1"
392+
attribute2="value2"
393+
attribute3="value3">
394+
<child />
395+
<child />
396+
</robot>
397+
```
398+
***

package-lock.json

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@
257257
"markdownDescription": "Split multiple attributes each onto a new line. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatsplitattributes%22%7D%5D) for more information.",
258258
"scope": "window"
259259
},
260+
"xml.format.splitAttributesIndentSize": {
261+
"type": "number",
262+
"default": 2,
263+
"markdownDescription": "How many levels to indent the attributes by when `#xml.format.splitAttributes#` is `true`. Default value is 2. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatsplitattributesindentsize%22%7D%5D) for more information"
264+
},
260265
"xml.preferences.quoteStyle": {
261266
"type": "string",
262267
"enum": [

0 commit comments

Comments
 (0)