From 939569a5d2398e0413ce03bb72bcf37def2dc123 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 31 May 2018 22:15:29 -0400 Subject: [PATCH] Update Existing Config Properties Issue: #184 --- package.json | 4 +- src/common/configuration.ts | 69 +++++++++++-------- src/extension.ts | 2 +- src/formatting/xml-formatter.ts | 2 +- src/formatting/xml-formatting-options.ts | 8 +-- src/tree-view/xml-tree-data-provider.ts | 6 +- src/xpath/commands/evaluateXPath.ts | 4 +- .../commands/executeXQuery.ts | 8 +-- 8 files changed, 56 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 5362bf2..d286c4f 100644 --- a/package.json +++ b/package.json @@ -156,13 +156,13 @@ "description": "Command-line arguments to pass to the executable.", "scope": "application" }, - "xmlTools.xquery.inputFileLimit": { + "xmlTools.xquery.inputFilesLimit": { "type": "integer", "default": 100, "description": "The maximum number of input files to enumerate.", "scope": "application" }, - "xmlTools.xquery.inputFileSearchPattern": { + "xmlTools.xquery.inputFilesSearchPattern": { "type": "string", "default": "**/*.xml", "description": "The pattern used to search for input XML files.", diff --git a/src/common/configuration.ts b/src/common/configuration.ts index b1461d0..95cdf52 100644 --- a/src/common/configuration.ts +++ b/src/common/configuration.ts @@ -1,69 +1,78 @@ import { workspace, Uri } from "vscode"; const ExtensionTopLevelSection = "xmlTools"; +const UseNewSettingsSection = "core.useNewSettings"; export class Configuration { - static get enableXmlTreeView(): boolean { - return this._getForWindow("enableXmlTreeView"); + static get treeViewEnabled(): boolean { + return this._getForWindow("treeView.enabled", "enableXmlTreeView"); } - static get enableXmlTreeViewMetadata(): boolean { - return this._getForWindow("enableXmlTreeViewMetadata"); + static get treeViewShowMetadata(): boolean { + return this._getForWindow("treeView.showMetadata", "enableXmlTreeViewMetadata"); } - static get enableXmlTreeViewCursorSync(): boolean { - return this._getForWindow("enableXmlTreeViewCursorSync"); + static get treeViewSyncCursor(): boolean { + return this._getForWindow("treeView.syncCursor", "enableXmlTreeViewCursorSync"); } - static get ignoreDefaultNamespace(): boolean { - return this._getForWindow("ignoreDefaultNamespace"); + static get xpathIgnoreDefaultNamespace(): boolean { + return this._getForWindow("xpath.ignoreDefaultNamespace", "ignoreDefaultNamespace"); } - static get persistXPathQuery(): boolean { - return this._getForWindow("persistXPathQuery"); + static get xpathRememberLastQuery(): boolean { + return this._getForWindow("xpath.rememberLastQuery", "persistXPathQuery"); } - static get xmlFormatterImplementation(): string { - return this._getForWindow("xmlFormatterImplementation"); + static get formatterImplementation(): string { + return this._getForWindow("formatter.implementation", "xmlFormatterImplementation"); } - static get xqueryExecutionArguments(): string[] { - return this._getForWindow("xqueryExecutionArguments"); + static get xqueryExecutableArgs(): string[] { + return this._getForWindow("xquery.executableArgs", "xqueryExecutionArguments"); } - static get xqueryExecutionEngine(): string { - return this._getForWindow("xqueryExecutionEngine"); + static get xqueryExecutable(): string { + return this._getForWindow("xquery.executable", "xqueryExecutionEngine"); } - static get xqueryExecutionInputLimit(): number { - return this._getForWindow("xqueryExecutionInputLimit"); + static get xqueryInputFilesLimit(): number { + return this._getForWindow("xquery.inputFilesLimit", "xqueryExecutionInputLimit"); } - static get xqueryExecutionInputSearchPattern(): string { - return this._getForWindow("xqueryExecutionInputSearchPattern"); + static get xqueryInputFilesSearchPattern(): string { + return this._getForWindow("xquery.inputFilesSearchPattern", "xqueryExecutionInputSearchPattern"); } - static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean { - return this._getForResource("enforcePrettySelfClosingTagOnFormat", resource); + static formatterAddSpaceBeforeSelfClose(resource: Uri): boolean { + return this._getForResource("formatter.addSpaceBeforeSelfClose", resource, "enforcePrettySelfClosingTagOnFormat"); } - static removeCommentsOnMinify(resource: Uri): boolean { - return this._getForResource("removeCommentsOnMinify", resource); + static formatterRemoveCommentsOnMinify(resource: Uri): boolean { + return this._getForResource("formatter.removeCommentsOnMinify", resource, "removeCommentsOnMinify"); } - static splitAttributesOnFormat(resource: Uri): boolean { - return this._getForResource("splitAttributesOnFormat", resource); + static formatterSplitAttributes(resource: Uri): boolean { + return this._getForResource("formatter.splitAttributes", resource, "splitAttributesOnFormat"); } - static splitXmlnsOnFormat(resource: Uri): boolean { - return this._getForResource("splitXmlnsOnFormat", resource); + static formatterSplitXmlnsAttributes(resource: Uri): boolean { + return this._getForResource("formatter.splitXmlnsAttributes", resource, "splitXmlnsOnFormat"); } - private static _getForResource(section: string, resource: Uri): T { + private static _getForResource(section: string, resource: Uri, oldSection?: string): T { + if (oldSection && !workspace.getConfiguration(ExtensionTopLevelSection).get(UseNewSettingsSection)) { + section = oldSection; + } + return workspace.getConfiguration(ExtensionTopLevelSection, resource).get(section); } - private static _getForWindow(section: string): T { + private static _getForWindow(section: string, oldSection?: string): T { + if (oldSection && !workspace.getConfiguration(ExtensionTopLevelSection).get(UseNewSettingsSection)) { + section = oldSection; + } + return workspace.getConfiguration(ExtensionTopLevelSection).get(section); } } diff --git a/src/extension.ts b/src/extension.ts index ee975af..e7a30a3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -47,7 +47,7 @@ export function activate(context: ExtensionContext) { treeDataProvider: treeViewDataProvider }); - if (Configuration.enableXmlTreeViewCursorSync) { + if (Configuration.treeViewSyncCursor) { window.onDidChangeTextEditorSelection(x => { if (x.kind === TextEditorSelectionChangeKind.Mouse && x.selections.length > 0) { treeView.reveal(treeViewDataProvider.getNodeAtPosition(x.selections[0].start)); diff --git a/src/formatting/xml-formatter.ts b/src/formatting/xml-formatter.ts index 01fb9ae..c32fc33 100644 --- a/src/formatting/xml-formatter.ts +++ b/src/formatting/xml-formatter.ts @@ -20,7 +20,7 @@ export class XmlFormatterFactory { return XmlFormatterFactory._xmlFormatter; } - const xmlFormatterImplementationSetting = Configuration.xmlFormatterImplementation; + const xmlFormatterImplementationSetting = Configuration.formatterImplementation; let xmlFormatterImplementation: XmlFormatter; switch (xmlFormatterImplementationSetting) { diff --git a/src/formatting/xml-formatting-options.ts b/src/formatting/xml-formatting-options.ts index 06782a1..f7fa9c1 100644 --- a/src/formatting/xml-formatting-options.ts +++ b/src/formatting/xml-formatting-options.ts @@ -16,11 +16,11 @@ export class XmlFormattingOptionsFactory { static getXmlFormattingOptions(formattingOptions: FormattingOptions, document: TextDocument): XmlFormattingOptions { return { editorOptions: formattingOptions, - enforcePrettySelfClosingTagOnFormat: Configuration.enforcePrettySelfClosingTagOnFormat(document.uri), + enforcePrettySelfClosingTagOnFormat: Configuration.formatterAddSpaceBeforeSelfClose(document.uri), newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n", - removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri), - splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri), - splitXmlnsOnFormat: Configuration.splitXmlnsOnFormat(document.uri) + removeCommentsOnMinify: Configuration.formatterRemoveCommentsOnMinify(document.uri), + splitAttributesOnFormat: Configuration.formatterSplitAttributes(document.uri), + splitXmlnsOnFormat: Configuration.formatterSplitXmlnsAttributes(document.uri) }; } } diff --git a/src/tree-view/xml-tree-data-provider.ts b/src/tree-view/xml-tree-data-provider.ts index 106d0a1..5526c31 100644 --- a/src/tree-view/xml-tree-data-provider.ts +++ b/src/tree-view/xml-tree-data-provider.ts @@ -34,8 +34,8 @@ export class XmlTreeDataProvider implements TreeDataProvider { } getTreeItem(element: Node): TreeItem | Thenable { - const enableMetadata = Configuration.enableXmlTreeViewMetadata; - const enableSync = Configuration.enableXmlTreeViewCursorSync; + const enableMetadata = Configuration.treeViewShowMetadata; + const enableSync = Configuration.treeViewSyncCursor; const treeItem = new TreeItem(element.localName); @@ -138,7 +138,7 @@ export class XmlTreeDataProvider implements TreeDataProvider { return; } - const enableTreeView = Configuration.enableXmlTreeView; + const enableTreeView = Configuration.treeViewEnabled; NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, enableTreeView); diff --git a/src/xpath/commands/evaluateXPath.ts b/src/xpath/commands/evaluateXPath.ts index bc22d97..fcb5e5a 100644 --- a/src/xpath/commands/evaluateXPath.ts +++ b/src/xpath/commands/evaluateXPath.ts @@ -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.persistXPathQuery; + const persistQueries = Configuration.xpathRememberLastQuery; // 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.ignoreDefaultNamespace; + const ignoreDefaultNamespace = Configuration.xpathIgnoreDefaultNamespace; // run the query const xml = editor.document.getText(); diff --git a/src/xquery-execution/commands/executeXQuery.ts b/src/xquery-execution/commands/executeXQuery.ts index a74ed0e..7f295cb 100644 --- a/src/xquery-execution/commands/executeXQuery.ts +++ b/src/xquery-execution/commands/executeXQuery.ts @@ -15,8 +15,8 @@ export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): P return; } - const executable = Configuration.xqueryExecutionEngine; - let args = Configuration.xqueryExecutionArguments || []; + const executable = Configuration.xqueryExecutable; + let args = Configuration.xqueryExecutableArgs || []; 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.xqueryExecutionInputSearchPattern; - const inputLimit = Configuration.xqueryExecutionInputLimit; + const searchPattern = Configuration.xqueryInputFilesSearchPattern; + const inputLimit = Configuration.xqueryInputFilesLimit; const files = await workspace.findFiles(searchPattern, "", inputLimit);