Revert Settings Changes

I'll come back to this later after some better planning.

Issue: #184
This commit is contained in:
Josh Johnson 2018-06-11 18:29:35 -04:00
parent 939569a5d2
commit de1fff2e80
8 changed files with 60 additions and 171 deletions

View File

@ -68,160 +68,58 @@
"title": "XML Tools Configuration",
"type": "object",
"properties": {
"xmlTools.core.useNewSettings": {
"type": "boolean",
"default": false,
"description": "Enables use of the new 'nested' settings instead of the current 'flattened' settings."
},
"xmlTools.formatter.addSpaceBeforeSelfClose": {
"type": "boolean",
"default": true,
"description": "Ensures a space exists before the '/>' in self-closing tags.",
"scope": "resource"
},
"xmlTools.formatter.implementation": {
"type": "string",
"default": "v2",
"description": "Defines the XML formatter implementation used for formatting and minification.",
"enum": [
"classic",
"v2"
],
"scope": "application"
},
"xmlTools.formatter.splitAttributes": {
"type": "boolean",
"default": false,
"description": "Places each attribute (except the first) on a new line. Includes xmlns attributes.",
"scope": "resource"
},
"xmlTools.formatter.splitXmlnsAttributes": {
"type": "boolean",
"default": false,
"description": "Places each xmlns attribute on a new line.",
"scope": "resource"
},
"xmlTools.formatter.stripCommentsOnMinify": {
"type": "boolean",
"default": false,
"description": "Removes comments from XML during minification.",
"scope": "resource"
},
"xmlTools.treeView.enabled": {
"type": "boolean",
"default": true,
"description": "Enables the XML Tree View feature.",
"scope": "application"
},
"xmlTools.treeView.showMetadata": {
"type": "boolean",
"default": true,
"description": "Displays attributes such as 'children' and 'attributes' counts in the XML tree view.",
"scope": "application"
},
"xmlTools.treeView.syncCursor": {
"type": "boolean",
"default": false,
"description": "Reveals an element or atribute in the tree view when clicked in the editor.",
"scope": "application"
},
"xmlTools.xpath.ignoreDefaultNamespace": {
"type": "boolean",
"default": true,
"description": "Ignores default xmlns attributes.",
"scope": "application"
},
"xmlTools.xpath.rememberLastQuery": {
"type": "boolean",
"default": true,
"description": "Remembers the last query you executed for the current file.",
"scope": "application"
},
"xmlTools.xquery.executable": {
"type": "string",
"default": true,
"description": "The full path to the executable to use for executing scripts.",
"scope": "application"
},
"xmlTools.xquery.executableArgs": {
"type": "array",
"default": [
"-xquery",
"$(script)",
"-in",
"$(input)",
"-out",
"$(input).output.xml"
],
"description": "Command-line arguments to pass to the executable.",
"scope": "application"
},
"xmlTools.xquery.inputFilesLimit": {
"type": "integer",
"default": 100,
"description": "The maximum number of input files to enumerate.",
"scope": "application"
},
"xmlTools.xquery.inputFilesSearchPattern": {
"type": "string",
"default": "**/*.xml",
"description": "The pattern used to search for input XML files.",
"scope": "application"
},
"xmlTools.enableXmlTreeView": {
"type": "boolean",
"default": true,
"description": "Deprecated. Use 'xmlTools.treeView.enabled' instead.",
"description": "Enables the XML Document view in the explorer for XML documents.",
"scope": "window"
},
"xmlTools.enableXmlTreeViewMetadata": {
"type": "boolean",
"default": true,
"description": "Deprecated. Use 'xmlTools.treeView.showMetadata' instead.",
"description": "Enables attribute and child element counts in the XML Document view.",
"scope": "window"
},
"xmlTools.enableXmlTreeViewCursorSync": {
"type": "boolean",
"default": false,
"description": "Deprecated. Use 'xmlTools.treeView.syncCursor' instead.",
"description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
"scope": "window"
},
"xmlTools.enforcePrettySelfClosingTagOnFormat": {
"type": "boolean",
"default": false,
"description": "Deprecated. Use 'xmlTools.formatter.addSpaceBeforeSelfClose' instead.",
"description": "Enforces a space before the forward slash at the end of a self-closing XML tag.",
"scope": "resource"
},
"xmlTools.ignoreDefaultNamespace": {
"type": "boolean",
"default": true,
"description": "Deprecated. Use 'xmlTools.xpath.ignoreDefaultNamespace' instead.",
"description": "Ignore default xmlns attributes when evaluating XPath.",
"scope": "window"
},
"xmlTools.persistXPathQuery": {
"type": "boolean",
"default": true,
"description": "Deprecated. Use 'xmlTools.xpath.rememberLastQuery' instead.",
"description": "Remember the last XPath query used.",
"scope": "window"
},
"xmlTools.removeCommentsOnMinify": {
"type": "boolean",
"default": false,
"description": "Deprecated. Use 'xmlTools.formatter.removeCommentsOnMinify' instead.",
"description": "Remove XML comments during minification.",
"scope": "resource"
},
"xmlTools.splitAttributesOnFormat": {
"type": "boolean",
"default": false,
"description": "Deprecated. Use 'xmlTools.formatter.splitAttributes' instead.",
"description": "Put each attribute on a new line when formatting XML. Overrides `xmlTools.splitXmlsOnFormat` if set to `true`.",
"scope": "resource"
},
"xmlTools.splitXmlnsOnFormat": {
"type": "boolean",
"default": true,
"description": "Deprecated. Use 'xmlTools.formatter.splitXmlnsAttributes' instead.",
"description": "Put each xmlns attribute on a new line when formatting XML.",
"scope": "resource"
},
"xmlTools.xmlFormatterImplementation": {
@ -231,7 +129,7 @@
"v2"
],
"default": "v2",
"description": "Deprecated. Use 'xmlTools.formatter.implementation' instead.",
"description": "Supported XML Formatters: classic",
"scope": "window"
},
"xmlTools.xqueryExecutionArguments": {
@ -242,27 +140,27 @@
"-in",
"$(input)",
"-out",
"$(input).output.xml"
"$(input.output.xml"
],
"description": "Deprecated. Use 'xmlTools.xquery.executableArgs' instead.",
"description": "Arguments to be passed to the XQuery execution engine.",
"scope": "window"
},
"xmlTools.xqueryExecutionEngine": {
"type": "string",
"default": "",
"description": "Deprecated. Use 'xmlTools.xquery.executable' instead.",
"description": "The full path to the executable to run when executing XQuery scripts.",
"scope": "window"
},
"xmlTools.xqueryExecutionInputLimit": {
"type": "integer",
"default": 100,
"description": "Deprecated. Use 'xmlTools.xquery.inputFileLimit' instead.",
"description": "The maximum number of input files to enumerate when executing XQuery scripts.",
"scope": "window"
},
"xmlTools.xqueryExecutionInputSearchPattern": {
"type": "string",
"default": "**/*.xml",
"description": "Deprecated. Use 'xmlTools.xquery.inputFileSearchPattern' instead.",
"description": "The pattern used to search for input XML files when executing XQuery scripts.",
"scope": "window"
}
}

View File

@ -1,78 +1,69 @@
import { workspace, Uri } from "vscode";
const ExtensionTopLevelSection = "xmlTools";
const UseNewSettingsSection = "core.useNewSettings";
export class Configuration {
static get treeViewEnabled(): boolean {
return this._getForWindow<boolean>("treeView.enabled", "enableXmlTreeView");
static get enableXmlTreeView(): boolean {
return this._getForWindow<boolean>("enableXmlTreeView");
}
static get treeViewShowMetadata(): boolean {
return this._getForWindow<boolean>("treeView.showMetadata", "enableXmlTreeViewMetadata");
static get enableXmlTreeViewMetadata(): boolean {
return this._getForWindow<boolean>("enableXmlTreeViewMetadata");
}
static get treeViewSyncCursor(): boolean {
return this._getForWindow<boolean>("treeView.syncCursor", "enableXmlTreeViewCursorSync");
static get enableXmlTreeViewCursorSync(): boolean {
return this._getForWindow<boolean>("enableXmlTreeViewCursorSync");
}
static get xpathIgnoreDefaultNamespace(): boolean {
return this._getForWindow<boolean>("xpath.ignoreDefaultNamespace", "ignoreDefaultNamespace");
static get ignoreDefaultNamespace(): boolean {
return this._getForWindow<boolean>("ignoreDefaultNamespace");
}
static get xpathRememberLastQuery(): boolean {
return this._getForWindow<boolean>("xpath.rememberLastQuery", "persistXPathQuery");
static get persistXPathQuery(): boolean {
return this._getForWindow<boolean>("persistXPathQuery");
}
static get formatterImplementation(): string {
return this._getForWindow<string>("formatter.implementation", "xmlFormatterImplementation");
static get xmlFormatterImplementation(): string {
return this._getForWindow<string>("xmlFormatterImplementation");
}
static get xqueryExecutableArgs(): string[] {
return this._getForWindow<string[]>("xquery.executableArgs", "xqueryExecutionArguments");
static get xqueryExecutionArguments(): string[] {
return this._getForWindow<string[]>("xqueryExecutionArguments");
}
static get xqueryExecutable(): string {
return this._getForWindow<string>("xquery.executable", "xqueryExecutionEngine");
static get xqueryExecutionEngine(): string {
return this._getForWindow<string>("xqueryExecutionEngine");
}
static get xqueryInputFilesLimit(): number {
return this._getForWindow<number>("xquery.inputFilesLimit", "xqueryExecutionInputLimit");
static get xqueryExecutionInputLimit(): number {
return this._getForWindow<number>("xqueryExecutionInputLimit");
}
static get xqueryInputFilesSearchPattern(): string {
return this._getForWindow<string>("xquery.inputFilesSearchPattern", "xqueryExecutionInputSearchPattern");
static get xqueryExecutionInputSearchPattern(): string {
return this._getForWindow<string>("xqueryExecutionInputSearchPattern");
}
static formatterAddSpaceBeforeSelfClose(resource: Uri): boolean {
return this._getForResource<boolean>("formatter.addSpaceBeforeSelfClose", resource, "enforcePrettySelfClosingTagOnFormat");
static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean {
return this._getForResource<boolean>("enforcePrettySelfClosingTagOnFormat", resource);
}
static formatterRemoveCommentsOnMinify(resource: Uri): boolean {
return this._getForResource<boolean>("formatter.removeCommentsOnMinify", resource, "removeCommentsOnMinify");
static removeCommentsOnMinify(resource: Uri): boolean {
return this._getForResource<boolean>("removeCommentsOnMinify", resource);
}
static formatterSplitAttributes(resource: Uri): boolean {
return this._getForResource<boolean>("formatter.splitAttributes", resource, "splitAttributesOnFormat");
static splitAttributesOnFormat(resource: Uri): boolean {
return this._getForResource<boolean>("splitAttributesOnFormat", resource);
}
static formatterSplitXmlnsAttributes(resource: Uri): boolean {
return this._getForResource<boolean>("formatter.splitXmlnsAttributes", resource, "splitXmlnsOnFormat");
static splitXmlnsOnFormat(resource: Uri): boolean {
return this._getForResource<boolean>("splitXmlnsOnFormat", resource);
}
private static _getForResource<T>(section: string, resource: Uri, oldSection?: string): T {
if (oldSection && !workspace.getConfiguration(ExtensionTopLevelSection).get<boolean>(UseNewSettingsSection)) {
section = oldSection;
}
private static _getForResource<T>(section: string, resource: Uri): T {
return workspace.getConfiguration(ExtensionTopLevelSection, resource).get<T>(section);
}
private static _getForWindow<T>(section: string, oldSection?: string): T {
if (oldSection && !workspace.getConfiguration(ExtensionTopLevelSection).get<boolean>(UseNewSettingsSection)) {
section = oldSection;
}
private static _getForWindow<T>(section: string): T {
return workspace.getConfiguration(ExtensionTopLevelSection).get<T>(section);
}
}

View File

@ -47,7 +47,7 @@ export function activate(context: ExtensionContext) {
treeDataProvider: treeViewDataProvider
});
if (Configuration.treeViewSyncCursor) {
if (Configuration.enableXmlTreeViewCursorSync) {
window.onDidChangeTextEditorSelection(x => {
if (x.kind === TextEditorSelectionChangeKind.Mouse && x.selections.length > 0) {
treeView.reveal(treeViewDataProvider.getNodeAtPosition(x.selections[0].start));

View File

@ -20,7 +20,7 @@ export class XmlFormatterFactory {
return XmlFormatterFactory._xmlFormatter;
}
const xmlFormatterImplementationSetting = Configuration.formatterImplementation;
const xmlFormatterImplementationSetting = Configuration.xmlFormatterImplementation;
let xmlFormatterImplementation: XmlFormatter;
switch (xmlFormatterImplementationSetting) {

View File

@ -16,11 +16,11 @@ export class XmlFormattingOptionsFactory {
static getXmlFormattingOptions(formattingOptions: FormattingOptions, document: TextDocument): XmlFormattingOptions {
return {
editorOptions: formattingOptions,
enforcePrettySelfClosingTagOnFormat: Configuration.formatterAddSpaceBeforeSelfClose(document.uri),
enforcePrettySelfClosingTagOnFormat: Configuration.enforcePrettySelfClosingTagOnFormat(document.uri),
newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n",
removeCommentsOnMinify: Configuration.formatterRemoveCommentsOnMinify(document.uri),
splitAttributesOnFormat: Configuration.formatterSplitAttributes(document.uri),
splitXmlnsOnFormat: Configuration.formatterSplitXmlnsAttributes(document.uri)
removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri),
splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri),
splitXmlnsOnFormat: Configuration.splitXmlnsOnFormat(document.uri)
};
}
}

View File

@ -34,8 +34,8 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
}
getTreeItem(element: Node): TreeItem | Thenable<TreeItem> {
const enableMetadata = Configuration.treeViewShowMetadata;
const enableSync = Configuration.treeViewSyncCursor;
const enableMetadata = Configuration.enableXmlTreeViewMetadata;
const enableSync = Configuration.enableXmlTreeViewCursorSync;
const treeItem = new TreeItem(element.localName);
@ -138,7 +138,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
return;
}
const enableTreeView = Configuration.treeViewEnabled;
const enableTreeView = Configuration.enableXmlTreeView;
NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, enableTreeView);

View File

@ -21,7 +21,7 @@ export async function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): P
const memento = ExtensionState.workspace || ExtensionState.global;
// get the xpath persistence setting
const persistQueries = Configuration.xpathRememberLastQuery;
const persistQueries = Configuration.persistXPathQuery;
// get the last query if there is one for this document
// if not, try pulling the last query ran, regardless of document
@ -47,7 +47,7 @@ export async function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): P
return;
}
const ignoreDefaultNamespace = Configuration.xpathIgnoreDefaultNamespace;
const ignoreDefaultNamespace = Configuration.ignoreDefaultNamespace;
// run the query
const xml = editor.document.getText();

View File

@ -15,8 +15,8 @@ export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): P
return;
}
const executable = Configuration.xqueryExecutable;
let args = Configuration.xqueryExecutableArgs || [];
const executable = Configuration.xqueryExecutionEngine;
let args = Configuration.xqueryExecutionArguments || [];
if (!executable || executable === "") {
const action = await window.showWarningMessage("An XQuery execution engine has not been defined.", "Define Now");
@ -31,8 +31,8 @@ export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): P
let inputFile: Uri;
disposable = window.setStatusBarMessage("Searching for XML files in folder...");
const searchPattern = Configuration.xqueryInputFilesSearchPattern;
const inputLimit = Configuration.xqueryInputFilesLimit;
const searchPattern = Configuration.xqueryExecutionInputSearchPattern;
const inputLimit = Configuration.xqueryExecutionInputLimit;
const files = await workspace.findFiles(searchPattern, "", inputLimit);