Add Linearization

This commit is contained in:
Josh Johnson 2015-11-22 02:37:00 -05:00
parent 30e8222717
commit 4c1e6d05b9
4 changed files with 31 additions and 14 deletions

View file

@ -1,22 +1,22 @@
'use strict';
import { TextEditor, TextEditorEdit, TextDocument, Position, Range } from 'vscode';
import { TextEditor, TextEditorEdit } from 'vscode';
import { getRangeForDocument } from '../utils/RangeUtils';
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
let range = getRangeForDocument(editor.document);
edit.replace(range, pretty);
}
export function linearizeXml(editor: TextEditor, edit: TextEditorEdit): void {
let current = editor.document.getText();
let linear = pd.xmlmin(current);
let range = getRangeForDocument(editor.document);
edit.replace(range, linear);
}