v1.8.0
This commit is contained in:
Josh Johnson 2017-06-01 22:13:52 -04:00 committed by GitHub
commit 181233529f
3 changed files with 47 additions and 3 deletions

View File

@ -2,7 +2,7 @@
"name": "xml", "name": "xml",
"displayName": "XML Tools", "displayName": "XML Tools",
"description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code", "description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code",
"version": "1.7.0", "version": "1.8.0",
"publisher": "DotJoshJohnson", "publisher": "DotJoshJohnson",
"author": { "author": {
"name": "Josh Johnson", "name": "Josh Johnson",
@ -49,6 +49,10 @@
{ {
"command": "xmlTools.viewXmlTree", "command": "xmlTools.viewXmlTree",
"title": "XML Tools: View XML Tree" "title": "XML Tools: View XML Tree"
},
{
"command": "xmlTools.formatAsXml",
"title": "XML Tools: Format as XML"
} }
], ],
"configuration": { "configuration": {
@ -120,7 +124,8 @@
"onCommand:xmlTools.minifyXml", "onCommand:xmlTools.minifyXml",
"onCommand:xmlTools.evaluateXPath", "onCommand:xmlTools.evaluateXPath",
"onCommand:xmlTools.executeXQuery", "onCommand:xmlTools.executeXQuery",
"onCommand:xmlTools.viewXmlTree" "onCommand:xmlTools.viewXmlTree",
"onCommand:xmlTools.formatAsXml"
], ],
"devDependencies": { "devDependencies": {
"vscode": "^0.11.8", "vscode": "^0.11.8",

View File

@ -8,6 +8,7 @@ import { XmlFormatter } from './services/XmlFormatter';
import { XPathFeatureProvider } from './providers/XPath'; import { XPathFeatureProvider } from './providers/XPath';
import { XQueryExecutionProvider } from './providers/Execution'; import { XQueryExecutionProvider } from './providers/Execution';
import { XmlTreeDocumentContentProvider } from './providers/Content'; import { XmlTreeDocumentContentProvider } from './providers/Content';
import { XmlFormattingEditProvider } from './providers/Formatting';
const CFG_SECTION: string = 'xmlTools'; const CFG_SECTION: string = 'xmlTools';
const CFG_REMOVE_COMMENTS: string = 'removeCommentsOnMinify'; const CFG_REMOVE_COMMENTS: string = 'removeCommentsOnMinify';
@ -44,4 +45,41 @@ export class TextEditorCommands {
vsc.window.showErrorMessage(`The XML Tree could not be created: ${error}`); vsc.window.showErrorMessage(`The XML Tree could not be created: ${error}`);
} }
} }
static formatAsXml(editor: vsc.TextEditor, edit: vsc.TextEditorEdit): void {
let edits: vsc.TextEdit[];
let formattingEditProvider = new XmlFormattingEditProvider();
let formattingOptions: vsc.FormattingOptions = {
insertSpaces: editor.options.insertSpaces,
tabSize: editor.options.tabSize
};
// if the user has selected text, only format what is selected
// otherwise, attempt to format the entire document
if (!editor.selection.isEmpty) {
edits = formattingEditProvider.provideDocumentRangeFormattingEdits(editor.document, editor.selection, formattingOptions);
}
else {
edits = formattingEditProvider.provideDocumentFormattingEdits(editor.document, formattingOptions);
}
if (edits) {
for (let i = 0; i < edits.length; i++) {
editor.edit(async (editBuilder) => {
editBuilder.replace(edits[i].range, edits[i].newText);
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
await vsc.commands.executeCommand('cursorMove', {
to: 'left',
by: 'character'
});
await vsc.commands.executeCommand('cursorMove', {
to: 'right',
by: 'character'
});
});
}
}
}
} }

View File

@ -26,7 +26,8 @@ export function activate(ctx: vsc.ExtensionContext) {
vsc.commands.registerTextEditorCommand('xmlTools.minifyXml', TextEditorCommands.minifyXml), vsc.commands.registerTextEditorCommand('xmlTools.minifyXml', TextEditorCommands.minifyXml),
vsc.commands.registerTextEditorCommand('xmlTools.evaluateXPath', TextEditorCommands.evaluateXPath), vsc.commands.registerTextEditorCommand('xmlTools.evaluateXPath', TextEditorCommands.evaluateXPath),
vsc.commands.registerTextEditorCommand('xmlTools.executeXQuery', TextEditorCommands.executeXQuery), vsc.commands.registerTextEditorCommand('xmlTools.executeXQuery', TextEditorCommands.executeXQuery),
vsc.commands.registerTextEditorCommand('xmlTools.viewXmlTree', TextEditorCommands.viewXmlTree) vsc.commands.registerTextEditorCommand('xmlTools.viewXmlTree', TextEditorCommands.viewXmlTree),
vsc.commands.registerTextEditorCommand('xmlTools.formatAsXml', TextEditorCommands.formatAsXml)
); );
// register language feature providers // register language feature providers