Add Attribute Splitting

#116
This commit is contained in:
Josh Johnson 2018-01-28 12:09:57 -05:00
parent 8f0bf58462
commit 9941bafa74
5 changed files with 14 additions and 1 deletions

View File

@ -17,8 +17,9 @@
* `xmlTools.ignoreDefaultNamespace`: Ignore default xmlns attributes when evaluating XPath. * `xmlTools.ignoreDefaultNamespace`: Ignore default xmlns attributes when evaluating XPath.
* `xmlTools.persistXPathQuery`: Remember the last XPath query used. * `xmlTools.persistXPathQuery`: Remember the last XPath query used.
* `xmlTools.removeCommentsOnMinify`: Remove XML comments during minification. * `xmlTools.removeCommentsOnMinify`: Remove XML comments during minification.
* `xmlTools.splitAttributesOnFormat`: Put each attribute on a new line when formatting XML. Overrides `xmlTools.splitXmlsOnFormat` if set to `true`. (V2 Formatter Only)
* `xmlTools.splitXmlnsOnFormat`: Put each xmlns attribute on a new line when formatting XML. * `xmlTools.splitXmlnsOnFormat`: Put each xmlns attribute on a new line when formatting XML.
* `xmlTools.xmlFormatterImplementation`: Supported XML Formatters: `classic`. * `xmlTools.xmlFormatterImplementation`: Supported XML Formatters: `classic`, `v2`.
* `xmlTools.xqueryExecutionArguments`: Arguments to be passed to the XQuery execution engine. * `xmlTools.xqueryExecutionArguments`: Arguments to be passed to the XQuery execution engine.
* `xmlTools.xqueryExecutionEngine`: The full path to the executable to run when executing XQuery scripts. * `xmlTools.xqueryExecutionEngine`: The full path to the executable to run when executing XQuery scripts.

View File

@ -80,6 +80,12 @@
"description": "Remove XML comments during minification.", "description": "Remove XML comments during minification.",
"scope": "resource" "scope": "resource"
}, },
"xmlTools.splitAttributesOnFormat": {
"type": "boolean",
"default": false,
"description": "Put each attribute on a new line when formatting XML. Overrides `xmlTools.splitXmlsOnFormat` if set to `true`.",
"scope": "resource"
},
"xmlTools.splitXmlnsOnFormat": { "xmlTools.splitXmlnsOnFormat": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,

View File

@ -87,6 +87,10 @@ export class V2XmlFormatter implements XmlFormatter {
// entering StartTag.Attribute // entering StartTag.Attribute
else if (location === Location.StartTag && [" ", "/", ">"].indexOf(cc) === -1) { else if (location === Location.StartTag && [" ", "/", ">"].indexOf(cc) === -1) {
if (lastNonTextLocation === Location.AttributeValue && ((options.splitXmlnsOnFormat && xml.substr(i, 5).toLowerCase() === "xmlns") || options.splitAttributesOnFormat)) {
output += `${options.newLine}${this._getIndent(options, indentLevel)}`;
}
output += cc; output += cc;
lastNonTextLocation = location; lastNonTextLocation = location;
location = Location.Attribute; location = Location.Attribute;

View File

@ -31,6 +31,7 @@ export class XmlFormattingEditProvider implements DocumentFormattingEditProvider
editorOptions: options, editorOptions: options,
newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n", newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n",
removeCommentsOnMinify: this.workspaceConfiguration.get<boolean>("removeCommentsOnMinify"), removeCommentsOnMinify: this.workspaceConfiguration.get<boolean>("removeCommentsOnMinify"),
splitAttributesOnFormat: this.workspaceConfiguration.get<boolean>("splitAttributesOnFormat"),
splitXmlnsOnFormat: this.workspaceConfiguration.get<boolean>("splitXmlnsOnFormat") splitXmlnsOnFormat: this.workspaceConfiguration.get<boolean>("splitXmlnsOnFormat")
}); });

View File

@ -4,5 +4,6 @@ export interface XmlFormattingOptions {
editorOptions: FormattingOptions; editorOptions: FormattingOptions;
newLine: string; newLine: string;
removeCommentsOnMinify: boolean; removeCommentsOnMinify: boolean;
splitAttributesOnFormat: boolean;
splitXmlnsOnFormat: boolean; splitXmlnsOnFormat: boolean;
} }