Add "addNewLineAfterSelfClosingTag" Option

This commit is contained in:
Josh Johnson 2018-12-21 14:52:56 -05:00
parent be6bb72b82
commit de27295538
4 changed files with 20 additions and 3 deletions

View file

@ -78,6 +78,12 @@
"title": "XML Tools Configuration",
"type": "object",
"properties": {
"xmlTools.addNewLineAfterSelfClosingTag": {
"type": "boolean",
"default": false,
"description": "Adds a newline after self-closing XML tags on format.",
"scope": "resource"
},
"xmlTools.enableXmlTreeView": {
"type": "boolean",
"default": true,

View file

@ -43,6 +43,10 @@ export class Configuration {
return this._getForWindow<string>("xqueryExecutionInputSearchPattern");
}
static addNewLineAfterSelfClosingTag(resource: Uri): boolean {
return this._getForResource<boolean>("addNewLineAfterSelfClosingTag", resource);
}
static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean {
return this._getForResource<boolean>("enforcePrettySelfClosingTagOnFormat", resource);
}

View file

@ -1,7 +1,6 @@
import { EndOfLine, FormattingOptions, TextDocument } from "vscode";
import { Configuration } from "../common";
import * as constants from "../constants";
export interface XmlFormattingOptions {
editorOptions: FormattingOptions;
@ -11,6 +10,7 @@ export interface XmlFormattingOptions {
splitAttributesOnFormat: boolean;
splitXmlnsOnFormat: boolean;
initialIndentLevel?: number;
addNewLineAfterSelfClosingTag: boolean;
}
export class XmlFormattingOptionsFactory {
@ -22,7 +22,8 @@ export class XmlFormattingOptionsFactory {
removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri),
splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri),
splitXmlnsOnFormat: Configuration.splitXmlnsOnFormat(document.uri),
initialIndentLevel: 0
initialIndentLevel: 0,
addNewLineAfterSelfClosingTag: Configuration.addNewLineAfterSelfClosingTag(document.uri)
};
}
}

View file

@ -21,7 +21,9 @@ describe("V2XmlFormatter", () => {
newLine: "\r\n",
removeCommentsOnMinify: false,
splitAttributesOnFormat: false,
splitXmlnsOnFormat: true
splitXmlnsOnFormat: true,
addNewLineAfterSelfClosingTag: false
};
it("should handle basic XML", () => {
@ -97,7 +99,11 @@ describe("V2XmlFormatter", () => {
});
it("should optionally add line break after self-closing tag", () => {
options.addNewLineAfterSelfClosingTag = true;
testFormatter(xmlFormatter, options, "issue-235");
options.addNewLineAfterSelfClosingTag = false;
});
});