Add XML Formatter
This commit is contained in:
		
							parent
							
								
									bd6b6240a5
								
							
						
					
					
						commit
						704f6c9a36
					
				
					 3 changed files with 2120 additions and 1 deletions
				
			
		
							
								
								
									
										11
									
								
								package.json
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								package.json
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -29,6 +29,14 @@
 | 
			
		|||
		"Languages", "Other"
 | 
			
		||||
	],
 | 
			
		||||
	"main": "./src/main",
 | 
			
		||||
	"contributes": {
 | 
			
		||||
		"commands": [
 | 
			
		||||
			{
 | 
			
		||||
				"command": "xmltools.formatXml",
 | 
			
		||||
				"title": "Format XML"
 | 
			
		||||
			}
 | 
			
		||||
		]
 | 
			
		||||
	},
 | 
			
		||||
	"activationEvents": [
 | 
			
		||||
		"onLanguage:xml"
 | 
			
		||||
	],
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +46,8 @@
 | 
			
		|||
	},
 | 
			
		||||
	"dependencies": {
 | 
			
		||||
		"semver": "^5.1.0",
 | 
			
		||||
		"request": "^2.67.0"
 | 
			
		||||
		"request": "^2.67.0",
 | 
			
		||||
		"pretty-data": "^0.40.0"
 | 
			
		||||
	},
 | 
			
		||||
	"scripts": {
 | 
			
		||||
		"compile": "node ./node_modules/vscode/bin/compile -watch -p ./"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										22
									
								
								src/features/xmlFormatting.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/features/xmlFormatting.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
'use strict';
 | 
			
		||||
 | 
			
		||||
import { TextEditor, TextEditorEdit, TextDocument, Position, Range } from 'vscode';
 | 
			
		||||
 | 
			
		||||
let pd = require('pretty-data').pd;
 | 
			
		||||
 | 
			
		||||
export function formatXml(editor: TextEditor, edit: TextEditorEdit): void {
 | 
			
		||||
	let current = editor.document.getText();
 | 
			
		||||
	let pretty = pd.xml(current);
 | 
			
		||||
	
 | 
			
		||||
	// get the range for the entire document
 | 
			
		||||
	let lastLineIndex = (editor.document.lineCount - 1);
 | 
			
		||||
	let lastLine = editor.document.lineAt(lastLineIndex);
 | 
			
		||||
	let lastPosition = lastLine.rangeIncludingLineBreak.end;
 | 
			
		||||
	let range = new Range(new Position(0, 0), lastPosition);
 | 
			
		||||
	
 | 
			
		||||
	// validate the range to ensure it fits inside the document
 | 
			
		||||
	range = editor.document.validateRange(range);
 | 
			
		||||
	
 | 
			
		||||
	// replace the existing xml with the pretty xml
 | 
			
		||||
	edit.replace(range, pretty);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2088
									
								
								typings/node/node.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2088
									
								
								typings/node/node.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		
		Reference in a new issue