parent
							
								
									07b47c4748
								
							
						
					
					
						commit
						156e1ab435
					
				
					 5 changed files with 25 additions and 0 deletions
				
			
		|  | @ -86,6 +86,12 @@ | ||||||
|                     "description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.", |                     "description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.", | ||||||
|                     "scope": "window" |                     "scope": "window" | ||||||
|                 }, |                 }, | ||||||
|  |                 "xmlTools.enforcePrettySelfClosingTagOnFormat": { | ||||||
|  |                     "type": "boolean", | ||||||
|  |                     "default": false, | ||||||
|  |                     "description": "Enforces a space before the forward slash at the end of a self-closing XML tag.", | ||||||
|  |                     "scope": "resource" | ||||||
|  |                 }, | ||||||
|                 "xmlTools.ignoreDefaultNamespace": { |                 "xmlTools.ignoreDefaultNamespace": { | ||||||
|                     "type": "boolean", |                     "type": "boolean", | ||||||
|                     "default": true, |                     "default": true, | ||||||
|  |  | ||||||
|  | @ -43,6 +43,10 @@ export class Configuration { | ||||||
|         return this._getForWindow<string>("xqueryExecutionInputSearchPattern"); |         return this._getForWindow<string>("xqueryExecutionInputSearchPattern"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean { | ||||||
|  |         return this._getForResource<boolean>("enforcePrettySelfClosingTagOnFormat", resource); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     static removeCommentsOnMinify(resource: Uri): boolean { |     static removeCommentsOnMinify(resource: Uri): boolean { | ||||||
|         return this._getForResource<boolean>("removeCommentsOnMinify", resource); |         return this._getForResource<boolean>("removeCommentsOnMinify", resource); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -135,6 +135,14 @@ export class V2XmlFormatter implements XmlFormatter { | ||||||
|                 location = Location.StartTag; |                 location = Location.StartTag; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             // approaching the end of a self-closing tag where there was no whitespace (issue #149)
 | ||||||
|  |             else if ((location === Location.StartTag || location === Location.StartTagName) | ||||||
|  |                 && cc === "/" | ||||||
|  |                 && pc !== " " | ||||||
|  |                 && options.enforcePrettySelfClosingTagOnFormat) { | ||||||
|  |                     output += " /"; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             // exiting StartTag or StartTag.StartTagName, entering Text
 |             // exiting StartTag or StartTag.StartTagName, entering Text
 | ||||||
|             else if ((location === Location.StartTag || location === Location.StartTagName) && cc === ">") { |             else if ((location === Location.StartTag || location === Location.StartTagName) && cc === ">") { | ||||||
|                 // if this was a self-closing tag, we need to decrement the indent level and add a newLine
 |                 // if this was a self-closing tag, we need to decrement the indent level and add a newLine
 | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ import * as constants from "../constants"; | ||||||
| 
 | 
 | ||||||
| export interface XmlFormattingOptions { | export interface XmlFormattingOptions { | ||||||
|     editorOptions: FormattingOptions; |     editorOptions: FormattingOptions; | ||||||
|  |     enforcePrettySelfClosingTagOnFormat: boolean; | ||||||
|     newLine: string; |     newLine: string; | ||||||
|     removeCommentsOnMinify: boolean; |     removeCommentsOnMinify: boolean; | ||||||
|     splitAttributesOnFormat: boolean; |     splitAttributesOnFormat: boolean; | ||||||
|  | @ -15,6 +16,7 @@ export class XmlFormattingOptionsFactory { | ||||||
|     static getXmlFormattingOptions(formattingOptions: FormattingOptions, document: TextDocument): XmlFormattingOptions { |     static getXmlFormattingOptions(formattingOptions: FormattingOptions, document: TextDocument): XmlFormattingOptions { | ||||||
|         return { |         return { | ||||||
|             editorOptions: formattingOptions, |             editorOptions: formattingOptions, | ||||||
|  |             enforcePrettySelfClosingTagOnFormat: Configuration.enforcePrettySelfClosingTagOnFormat(document.uri), | ||||||
|             newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n", |             newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n", | ||||||
|             removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri), |             removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri), | ||||||
|             splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri), |             splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri), | ||||||
|  |  | ||||||
|  | @ -17,6 +17,7 @@ describe("V2XmlFormatter", () => { | ||||||
|                 insertSpaces: true, |                 insertSpaces: true, | ||||||
|                 tabSize: 4 |                 tabSize: 4 | ||||||
|             }, |             }, | ||||||
|  |             enforcePrettySelfClosingTagOnFormat: false, | ||||||
|             newLine: "\r\n", |             newLine: "\r\n", | ||||||
|             removeCommentsOnMinify: false, |             removeCommentsOnMinify: false, | ||||||
|             splitAttributesOnFormat: false, |             splitAttributesOnFormat: false, | ||||||
|  | @ -60,7 +61,11 @@ describe("V2XmlFormatter", () => { | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         it("should allow users to enforce space before self-closing tag slash", () => { |         it("should allow users to enforce space before self-closing tag slash", () => { | ||||||
|  |             options.enforcePrettySelfClosingTagOnFormat = true; | ||||||
|  | 
 | ||||||
|             testFormatter(xmlFormatter, options, "issue-149"); |             testFormatter(xmlFormatter, options, "issue-149"); | ||||||
|  | 
 | ||||||
|  |             options.enforcePrettySelfClosingTagOnFormat = false; | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue