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", "title": "XML Tools Configuration",
"type": "object", "type": "object",
"properties": { "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": { "xmlTools.enableXmlTreeView": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Deprecated. Use 'xmlTools.treeView.enabled' instead.", "description": "Enables the XML Document view in the explorer for XML documents.",
"scope": "window" "scope": "window"
}, },
"xmlTools.enableXmlTreeViewMetadata": { "xmlTools.enableXmlTreeViewMetadata": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Deprecated. Use 'xmlTools.treeView.showMetadata' instead.", "description": "Enables attribute and child element counts in the XML Document view.",
"scope": "window" "scope": "window"
}, },
"xmlTools.enableXmlTreeViewCursorSync": { "xmlTools.enableXmlTreeViewCursorSync": {
"type": "boolean", "type": "boolean",
"default": false, "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" "scope": "window"
}, },
"xmlTools.enforcePrettySelfClosingTagOnFormat": { "xmlTools.enforcePrettySelfClosingTagOnFormat": {
"type": "boolean", "type": "boolean",
"default": false, "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" "scope": "resource"
}, },
"xmlTools.ignoreDefaultNamespace": { "xmlTools.ignoreDefaultNamespace": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Deprecated. Use 'xmlTools.xpath.ignoreDefaultNamespace' instead.", "description": "Ignore default xmlns attributes when evaluating XPath.",
"scope": "window" "scope": "window"
}, },
"xmlTools.persistXPathQuery": { "xmlTools.persistXPathQuery": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Deprecated. Use 'xmlTools.xpath.rememberLastQuery' instead.", "description": "Remember the last XPath query used.",
"scope": "window" "scope": "window"
}, },
"xmlTools.removeCommentsOnMinify": { "xmlTools.removeCommentsOnMinify": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description": "Deprecated. Use 'xmlTools.formatter.removeCommentsOnMinify' instead.", "description": "Remove XML comments during minification.",
"scope": "resource" "scope": "resource"
}, },
"xmlTools.splitAttributesOnFormat": { "xmlTools.splitAttributesOnFormat": {
"type": "boolean", "type": "boolean",
"default": false, "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" "scope": "resource"
}, },
"xmlTools.splitXmlnsOnFormat": { "xmlTools.splitXmlnsOnFormat": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Deprecated. Use 'xmlTools.formatter.splitXmlnsAttributes' instead.", "description": "Put each xmlns attribute on a new line when formatting XML.",
"scope": "resource" "scope": "resource"
}, },
"xmlTools.xmlFormatterImplementation": { "xmlTools.xmlFormatterImplementation": {
@ -231,7 +129,7 @@
"v2" "v2"
], ],
"default": "v2", "default": "v2",
"description": "Deprecated. Use 'xmlTools.formatter.implementation' instead.", "description": "Supported XML Formatters: classic",
"scope": "window" "scope": "window"
}, },
"xmlTools.xqueryExecutionArguments": { "xmlTools.xqueryExecutionArguments": {
@ -242,27 +140,27 @@
"-in", "-in",
"$(input)", "$(input)",
"-out", "-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" "scope": "window"
}, },
"xmlTools.xqueryExecutionEngine": { "xmlTools.xqueryExecutionEngine": {
"type": "string", "type": "string",
"default": "", "default": "",
"description": "Deprecated. Use 'xmlTools.xquery.executable' instead.", "description": "The full path to the executable to run when executing XQuery scripts.",
"scope": "window" "scope": "window"
}, },
"xmlTools.xqueryExecutionInputLimit": { "xmlTools.xqueryExecutionInputLimit": {
"type": "integer", "type": "integer",
"default": 100, "default": 100,
"description": "Deprecated. Use 'xmlTools.xquery.inputFileLimit' instead.", "description": "The maximum number of input files to enumerate when executing XQuery scripts.",
"scope": "window" "scope": "window"
}, },
"xmlTools.xqueryExecutionInputSearchPattern": { "xmlTools.xqueryExecutionInputSearchPattern": {
"type": "string", "type": "string",
"default": "**/*.xml", "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" "scope": "window"
} }
} }

View File

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

View File

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

View File

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

View File

@ -16,11 +16,11 @@ 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.formatterAddSpaceBeforeSelfClose(document.uri), enforcePrettySelfClosingTagOnFormat: Configuration.enforcePrettySelfClosingTagOnFormat(document.uri),
newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n", newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n",
removeCommentsOnMinify: Configuration.formatterRemoveCommentsOnMinify(document.uri), removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri),
splitAttributesOnFormat: Configuration.formatterSplitAttributes(document.uri), splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri),
splitXmlnsOnFormat: Configuration.formatterSplitXmlnsAttributes(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> { getTreeItem(element: Node): TreeItem | Thenable<TreeItem> {
const enableMetadata = Configuration.treeViewShowMetadata; const enableMetadata = Configuration.enableXmlTreeViewMetadata;
const enableSync = Configuration.treeViewSyncCursor; const enableSync = Configuration.enableXmlTreeViewCursorSync;
const treeItem = new TreeItem(element.localName); const treeItem = new TreeItem(element.localName);
@ -138,7 +138,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
return; return;
} }
const enableTreeView = Configuration.treeViewEnabled; const enableTreeView = Configuration.enableXmlTreeView;
NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, enableTreeView); 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; const memento = ExtensionState.workspace || ExtensionState.global;
// get the xpath persistence setting // get the xpath persistence setting
const persistQueries = Configuration.xpathRememberLastQuery; const persistQueries = Configuration.persistXPathQuery;
// get the last query if there is one for this document // get the last query if there is one for this document
// if not, try pulling the last query ran, regardless of 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; return;
} }
const ignoreDefaultNamespace = Configuration.xpathIgnoreDefaultNamespace; const ignoreDefaultNamespace = Configuration.ignoreDefaultNamespace;
// run the query // run the query
const xml = editor.document.getText(); const xml = editor.document.getText();

View File

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