From de27295538f60bc1e62c710d92d73b975ba6be15 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Fri, 21 Dec 2018 14:52:56 -0500 Subject: [PATCH] Add "addNewLineAfterSelfClosingTag" Option --- package.json | 6 ++++++ src/common/configuration.ts | 4 ++++ src/formatting/xml-formatting-options.ts | 5 +++-- src/test/extension.test.ts | 8 +++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7ed5be4..b459a25 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/common/configuration.ts b/src/common/configuration.ts index b1461d0..179a52f 100644 --- a/src/common/configuration.ts +++ b/src/common/configuration.ts @@ -43,6 +43,10 @@ export class Configuration { return this._getForWindow("xqueryExecutionInputSearchPattern"); } + static addNewLineAfterSelfClosingTag(resource: Uri): boolean { + return this._getForResource("addNewLineAfterSelfClosingTag", resource); + } + static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean { return this._getForResource("enforcePrettySelfClosingTagOnFormat", resource); } diff --git a/src/formatting/xml-formatting-options.ts b/src/formatting/xml-formatting-options.ts index 7c5185a..301c1d9 100644 --- a/src/formatting/xml-formatting-options.ts +++ b/src/formatting/xml-formatting-options.ts @@ -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) }; } } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 07b57db..7aa3de5 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -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; }); });