The main purpose of this extension is to provide a standard way to format and sort tags for metadata files (with extension ".xml" ) on Salesforce orgs. The tags inside the XMLs are sorted in a fixed order following Salesforce-specific set of rules. The final goal is to be able to work easily with git using a repository shared by multiples developers, minimizing the number of conflicts detected at the time of doing the merges.
This is a formatter extension. It implements the Formatting API following the VS Code's guiding principles. The core benefit of using the extension API for implementing a formatter comes from the exposure of the Format Document and Format Selection actions. These actions are available in the editor context menu, bound to keyboard shortcuts, and visible in the Command Palette.
Install through VS Code extensions. Search for Salesforce XML Formatter
It can also be installed in VS Code: Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install SwagUp.sf-xml-formatter
To ensure that this extension is used over other extensions you may have installed, be sure to set it as the default formatter in your VS Code settings.
"[xml]": {
"editor.defaultFormatter": "SwagUp.sf-xml-formatter"
}
You can add the following line in your VS Code settings to automatically format all XML files on save.
"[xml]": {
"editor.defaultFormatter": "SwagUp.sf-xml-formatter",
"editor.formatOnSave": true
}
You can use the Formatting actions of VS Code: Format Document and Format Selection; or just use the configuration showed above in the Auto Format section to format on save.
This extension contributes the following settings:
sf-xml-formatter.format.enabled
: Enable/disable ability to format document. Default istrue
.
You can add the following line in your VS Code settings to disable the formatter.
"sf-xml-formatter.format.enabled": false
There is a command to open the docs:
SF XML FORMATTER: Open docs
. Do the following to open the repository with all the documentation.
Using Command Palette (CMD/CTRL + Shift + P) -> SF XML FORMATTER: Open docs