From 846a12898457fdc18af33d0271455c702e799b89 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 21 Jun 2017 00:30:16 -0400 Subject: [PATCH 1/4] Remove "use strict" Closes #107 --- src/Commands.ts | 2 -- src/Extension.ts | 2 -- src/providers/Completion.ts | 2 -- src/providers/Execution.ts | 2 -- src/providers/Formatting.ts | 2 -- src/providers/Linting.ts | 2 -- src/providers/XPath.ts | 2 -- src/services/ChildProcess.ts | 2 -- src/services/XPathEvaluator.ts | 2 -- src/services/XQueryCompleter.ts | 2 -- src/services/XQueryLinter.ts | 2 -- src/services/XmlFormatter.ts | 2 -- src/utils/RangeUtil.ts | 2 -- 13 files changed, 26 deletions(-) diff --git a/src/Commands.ts b/src/Commands.ts index 6cb3ef8..57731fe 100644 --- a/src/Commands.ts +++ b/src/Commands.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import * as ext from './Extension'; import * as xpath from 'xpath'; diff --git a/src/Extension.ts b/src/Extension.ts index 8570b99..74b4742 100644 --- a/src/Extension.ts +++ b/src/Extension.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import { TextEditorCommands } from './Commands'; import { XmlFormattingEditProvider } from './providers/Formatting'; diff --git a/src/providers/Completion.ts b/src/providers/Completion.ts index c969e7f..dad38d5 100644 --- a/src/providers/Completion.ts +++ b/src/providers/Completion.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import { XQueryCompleter, XQueryCompletionItem } from '../services/XQueryCompleter'; diff --git a/src/providers/Execution.ts b/src/providers/Execution.ts index 389f6fe..559dea1 100644 --- a/src/providers/Execution.ts +++ b/src/providers/Execution.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import { ChildProcess } from '../services/ChildProcess'; diff --git a/src/providers/Formatting.ts b/src/providers/Formatting.ts index b0756b5..bd3a900 100644 --- a/src/providers/Formatting.ts +++ b/src/providers/Formatting.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import { RangeUtil } from '../utils/RangeUtil'; import { XmlFormatter, IXmlFormatterOptions } from '../services/XmlFormatter'; diff --git a/src/providers/Linting.ts b/src/providers/Linting.ts index e2c755a..3f8992a 100644 --- a/src/providers/Linting.ts +++ b/src/providers/Linting.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import { XQueryLinter, XQueryDiagnostic } from '../services/XQueryLinter'; diff --git a/src/providers/XPath.ts b/src/providers/XPath.ts index fd54e84..adca124 100644 --- a/src/providers/XPath.ts +++ b/src/providers/XPath.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; import * as ext from '../Extension'; import { XPathEvaluator, EvaluatorResult, EvaluatorResultType } from '../services/XPathEvaluator'; diff --git a/src/services/ChildProcess.ts b/src/services/ChildProcess.ts index 1290a06..5af998e 100644 --- a/src/services/ChildProcess.ts +++ b/src/services/ChildProcess.ts @@ -1,5 +1,3 @@ -'use strict'; - let child_process = require('child_process'); export class ChildProcess { diff --git a/src/services/XPathEvaluator.ts b/src/services/XPathEvaluator.ts index 50979b2..b7a1a54 100644 --- a/src/services/XPathEvaluator.ts +++ b/src/services/XPathEvaluator.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as xpath from 'xpath'; let DOMParser = require('xmldom').DOMParser; diff --git a/src/services/XQueryCompleter.ts b/src/services/XQueryCompleter.ts index fcaf029..8bc4467 100644 --- a/src/services/XQueryCompleter.ts +++ b/src/services/XQueryCompleter.ts @@ -1,5 +1,3 @@ -'use strict'; - let XQLint = require('xqlint').XQLint; export class XQueryCompleter { diff --git a/src/services/XQueryLinter.ts b/src/services/XQueryLinter.ts index ba7db16..30e5c8a 100644 --- a/src/services/XQueryLinter.ts +++ b/src/services/XQueryLinter.ts @@ -1,5 +1,3 @@ -'use strict'; - let XQLint = require('xqlint').XQLint; export class XQueryLinter { diff --git a/src/services/XmlFormatter.ts b/src/services/XmlFormatter.ts index 6f4e314..349e1f7 100644 --- a/src/services/XmlFormatter.ts +++ b/src/services/XmlFormatter.ts @@ -1,5 +1,3 @@ -'use strict'; - // Based on pretty-data (https://github.com/vkiryukhin/pretty-data) export class XmlFormatter { constructor(options?: IXmlFormatterOptions) { diff --git a/src/utils/RangeUtil.ts b/src/utils/RangeUtil.ts index 8200162..ebb3dc6 100644 --- a/src/utils/RangeUtil.ts +++ b/src/utils/RangeUtil.ts @@ -1,5 +1,3 @@ -'use strict'; - import * as vsc from 'vscode'; export class RangeUtil { From 9272bae72eab85eba47c93b1245122b44b002de5 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Fri, 23 Jun 2017 20:57:51 -0400 Subject: [PATCH 2/4] Update Contribution Guide --- CONTRIBUTING.md | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44c3c7d..daa4f56 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,8 @@ Keep in mind that these are guidelines, not rules. Use your best judgement and f Please use the follow general workflow when making contributions to the code: 1. Fork the repository. -2. Create a feature branch or commit directly to the `develop` branch. -3. Create a pull request to request that your commits be merged to the `develop` branch of the `vscode-xml` repository. PRs submitted to the `master` branch will not be considered. +2. Create a feature branch and make your changes. +3. Create a pull request to request that your commits be merged to `master`. ## Building the Extension @@ -15,35 +15,29 @@ Please use the follow general workflow when making contributions to the code: 2. Run the `build` task in VS Code (`CTRL + SHIFT + B`) or start extension debugging (`F5`), which will run the `build` task for you. ## Style Guide +### Quotes +Use double quotes for strings whenever possible. + ### Imports -To keep *.ts files from getting too cluttered, use a namespace alias when pulling in more than 4 or 5 objects. As a general rule, always import the `vscode` namespace using the `vsc` alias for consistency. - -**Favor This** - -`import * as abc from 'abclib';` - -**Over This** - -`import { SomeType, AnotherType, BigClassWithCrazyName, IwantThisToo, VeryAppealingClass, Gimmee } from 'abclib';` +As a general rule, always import the `vscode` namespace using the `vsc` alias for consistency. ### Static Classes When possible, try to use a static class to wrap utility functions so you are importing the class, not just a function. -For libraries that do not follow this construct (such as the `xpath` module), *always* import the module using an alias (`import * as xpath from 'xpath'). +For libraries that do not follow this construct (such as the `xpath` module), *always* import the module using an alias (`import * as xpath from "xpath"). ### Constants Where applicable, try to use constants instead of inline strings and numbers. ## Implicit Types -Moving forward, the compiler is instructed (via tsconfig.json) to throw warnings if any expressions imply an "any" type. In other words, always use type declarations where applicable so it is clear what type is being used. +Moving forward, the compiler is instructed (via tsconfig.json) to throw warnings if any expressions imply an `any` type. In other words, always use type declarations where applicable so it is clear what type is being used. There is an exception to this guideline. If you are using a thrid party library that does not have a *.d.ts file available, you do not need to write one. Just ensure the API is documented (either in this repo or in the library's repo). - ## Folder Structure All TypeScript files should reside under the top `src` folder. Under this, there are several subfolders and top-level files defined below: ### providers This folder contains any classes that implement provider interfaces from the `vscode` namespace. This folder also contains any code that works directly with the -APIs exposed by the `vscode` namespace, such as user interaction or configuration access. Aside for the `vscode` module, no code in this folder should be dependent on +APIs exposed by the `vscode` namespace, such as user interaction or configuration access. Aside for the `vscode` module, no code in this folder should be directly dependent on any external NodeJS modules or libraries. ### services @@ -51,12 +45,10 @@ This folder contains any classes that perform actions/logic required by the prov dependent on external Node modules and libraries. ### utils -This folder contains any utility classes/functions that might be used by providers. +This folder contains any utility classes/functions. ### Commands.ts This file acts as an interface to all registered commands in the extension. If a substantial amount of code is required to implement a command, it should be moved to a provider and/or service. -Otherwise, if a command can be implemented in just a few lines, that code can be placed here. ### Extension.ts -Previously named `main.ts`, this is the primary entry point to the extension. Anything that needs done on activation or deactivation of the extension is done here. Both the workspace -and global `Memento` instances are exposed from this module, which can be used by providers as needed. +Previously named `main.ts`, this is the primary entry point to the extension. Anything that needs done on activation or deactivation of the extension is done here. Both the workspace and global `Memento` instances are exposed from this module, which can be used by providers as needed. From 6eb35d0a3767cc62e4e5e95af7dd6a4386adff90 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Fri, 23 Jun 2017 20:58:16 -0400 Subject: [PATCH 3/4] Remove Roadmap Link --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 1e2c266..1bf37c4 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,6 @@ Detailed release notes are available [here](https://github.com/DotJoshJohnson/vs ## Issues Run into a bug? Report it [here](https://github.com/DotJoshJohnson/vscode-xml/issues). -## Roadmap -Check out development progress [here](https://github.com/DotJoshJohnson/vscode-xml/projects/1). - ## Icon Credits Icons used in the XML Tree View are used under the Creative Commons 3.0 BY license. * "Code" icon by Dave Gandy from www.flaticon.com From 93b3083bbf5127de40777a3b4cb8e29c8cbbe244 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Fri, 23 Jun 2017 21:06:53 -0400 Subject: [PATCH 4/4] Switch to Double Quotes Closes #108 --- gulpfile.js | 10 +++---- src/Commands.ts | 32 ++++++++++----------- src/Extension.ts | 32 ++++++++++----------- src/providers/Completion.ts | 18 ++++++------ src/providers/Execution.ts | 50 ++++++++++++++++----------------- src/providers/Formatting.ts | 10 +++---- src/providers/Linting.ts | 6 ++-- src/providers/XPath.ts | 28 +++++++++--------- src/services/ChildProcess.ts | 12 ++++---- src/services/XPathEvaluator.ts | 8 +++--- src/services/XQueryCompleter.ts | 2 +- src/services/XQueryLinter.ts | 2 +- src/services/XmlFormatter.ts | 46 +++++++++++++++--------------- src/utils/RangeUtil.ts | 2 +- 14 files changed, 129 insertions(+), 129 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b57dcf2..e71a309 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,9 +1,9 @@ -var gulp = require('gulp'); +var gulp = require("gulp"); -var shell = require('gulp-shell'); +var shell = require("gulp-shell"); -gulp.task('compile-typescript', function () { - gulp.src('package.json').pipe(shell('tsc')); +gulp.task("compile-typescript", function () { + gulp.src("package.json").pipe(shell("tsc")); }); -gulp.task('build', ['compile-typescript']); \ No newline at end of file +gulp.task("build", ["compile-typescript"]); \ No newline at end of file diff --git a/src/Commands.ts b/src/Commands.ts index 57731fe..f09705f 100644 --- a/src/Commands.ts +++ b/src/Commands.ts @@ -1,14 +1,14 @@ -import * as vsc from 'vscode'; -import * as ext from './Extension'; -import * as xpath from 'xpath'; -import { RangeUtil } from './utils/RangeUtil'; -import { XmlFormatter } from './services/XmlFormatter'; -import { XPathFeatureProvider } from './providers/XPath'; -import { XQueryExecutionProvider } from './providers/Execution'; -import { XmlFormattingEditProvider } from './providers/Formatting'; +import * as vsc from "vscode"; +import * as ext from "./Extension"; +import * as xpath from "xpath"; +import { RangeUtil } from "./utils/RangeUtil"; +import { XmlFormatter } from "./services/XmlFormatter"; +import { XPathFeatureProvider } from "./providers/XPath"; +import { XQueryExecutionProvider } from "./providers/Execution"; +import { XmlFormattingEditProvider } from "./providers/Formatting"; -const CFG_SECTION: string = 'xmlTools'; -const CFG_REMOVE_COMMENTS: string = 'removeCommentsOnMinify'; +const CFG_SECTION: string = "xmlTools"; +const CFG_REMOVE_COMMENTS: string = "removeCommentsOnMinify"; export class TextEditorCommands { static minifyXml(editor: vsc.TextEditor, edit: vsc.TextEditorEdit): void { @@ -54,13 +54,13 @@ export class TextEditorCommands { 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: "left", + by: "character" }); - await vsc.commands.executeCommand('cursorMove', { - to: 'right', - by: 'character' + await vsc.commands.executeCommand("cursorMove", { + to: "right", + by: "character" }); }); } diff --git a/src/Extension.ts b/src/Extension.ts index 74b4742..2e600a9 100644 --- a/src/Extension.ts +++ b/src/Extension.ts @@ -1,30 +1,30 @@ -import * as vsc from 'vscode'; -import { TextEditorCommands } from './Commands'; -import { XmlFormattingEditProvider } from './providers/Formatting'; -import { XQueryLintingFeatureProvider } from './providers/Linting'; -import { XQueryCompletionItemProvider } from './providers/Completion'; +import * as vsc from "vscode"; +import { TextEditorCommands } from "./Commands"; +import { XmlFormattingEditProvider } from "./providers/Formatting"; +import { XQueryLintingFeatureProvider } from "./providers/Linting"; +import { XQueryCompletionItemProvider } from "./providers/Completion"; import { XmlTreeViewDataProvider } from "./providers/XmlTreeView"; export var GlobalState: vsc.Memento; export var WorkspaceState: vsc.Memento; -const LANG_XML: string = 'xml'; -const LANG_XSL: string = 'xsl'; -const LANG_XQUERY: string = 'xquery;' -const MEM_QUERY_HISTORY: string = 'xpathQueryHistory'; +const LANG_XML: string = "xml"; +const LANG_XSL: string = "xsl"; +const LANG_XQUERY: string = "xquery;" +const MEM_QUERY_HISTORY: string = "xpathQueryHistory"; export function activate(ctx: vsc.ExtensionContext) { - console.log('activate extension'); + console.log("activate extension"); // expose global and workspace state to the entire extension GlobalState = ctx.globalState; WorkspaceState = ctx.workspaceState; // register palette commands ctx.subscriptions.push( - vsc.commands.registerTextEditorCommand('xmlTools.minifyXml', TextEditorCommands.minifyXml), - vsc.commands.registerTextEditorCommand('xmlTools.evaluateXPath', TextEditorCommands.evaluateXPath), - vsc.commands.registerTextEditorCommand('xmlTools.executeXQuery', TextEditorCommands.executeXQuery), - vsc.commands.registerTextEditorCommand('xmlTools.formatAsXml', TextEditorCommands.formatAsXml) + vsc.commands.registerTextEditorCommand("xmlTools.minifyXml", TextEditorCommands.minifyXml), + vsc.commands.registerTextEditorCommand("xmlTools.evaluateXPath", TextEditorCommands.evaluateXPath), + vsc.commands.registerTextEditorCommand("xmlTools.executeXQuery", TextEditorCommands.executeXQuery), + vsc.commands.registerTextEditorCommand("xmlTools.formatAsXml", TextEditorCommands.formatAsXml) ); // register language feature providers @@ -32,7 +32,7 @@ export function activate(ctx: vsc.ExtensionContext) { vsc.languages.registerDocumentFormattingEditProvider([LANG_XML, LANG_XSL], new XmlFormattingEditProvider()), vsc.languages.registerDocumentRangeFormattingEditProvider([LANG_XML, LANG_XSL], new XmlFormattingEditProvider()), - vsc.languages.registerCompletionItemProvider(LANG_XQUERY, new XQueryCompletionItemProvider(), ':', '$') + vsc.languages.registerCompletionItemProvider(LANG_XQUERY, new XQueryCompletionItemProvider(), ":", "$") ); // listen to editor events (for linting) @@ -61,7 +61,7 @@ function _handleContextChange(editor: vsc.TextEditor): void { } switch (editor.document.languageId) { - case 'xquery': + case "xquery": XQueryLintingFeatureProvider.provideXQueryDiagnostics(editor); break; } diff --git a/src/providers/Completion.ts b/src/providers/Completion.ts index dad38d5..fcbad7c 100644 --- a/src/providers/Completion.ts +++ b/src/providers/Completion.ts @@ -1,5 +1,5 @@ -import * as vsc from 'vscode'; -import { XQueryCompleter, XQueryCompletionItem } from '../services/XQueryCompleter'; +import * as vsc from "vscode"; +import { XQueryCompleter, XQueryCompletionItem } from "../services/XQueryCompleter"; export class XQueryCompletionItemProvider implements vsc.CompletionItemProvider { provideCompletionItems(document: vsc.TextDocument, position: vsc.Position): vsc.CompletionItem[] { @@ -14,20 +14,20 @@ export class XQueryCompletionItemProvider implements vsc.CompletionItemProvider switch (completion.meta) { // functions (always qualified with a colon) - case 'function': + case "function": item.kind = vsc.CompletionItemKind.Function; - let funcStart = (completion.value.indexOf(':') + 1); - let funcEnd = completion.value.indexOf('('); + let funcStart = (completion.value.indexOf(":") + 1); + let funcEnd = completion.value.indexOf("("); item.insertText = completion.value.substring(funcStart, funcEnd); break; // variables and parameters (always qualified with a dollar sign) - case 'Let binding': - case 'Local variable': - case 'Window variable': - case 'Function parameter': + case "Let binding": + case "Local variable": + case "Window variable": + case "Function parameter": item.kind = vsc.CompletionItemKind.Variable; item.insertText = completion.value.substring(1); break; diff --git a/src/providers/Execution.ts b/src/providers/Execution.ts index 559dea1..1ac3dee 100644 --- a/src/providers/Execution.ts +++ b/src/providers/Execution.ts @@ -1,41 +1,41 @@ -import * as vsc from 'vscode'; -import { ChildProcess } from '../services/ChildProcess'; +import * as vsc from "vscode"; +import { ChildProcess } from "../services/ChildProcess"; -const CFG_SECTION: string = 'xmlTools'; -const CFG_XQEXEC: string = 'xqueryExecutionEngine'; -const CFG_XQARGS: string = 'xqueryExecutionArguments'; +const CFG_SECTION: string = "xmlTools"; +const CFG_XQEXEC: string = "xqueryExecutionEngine"; +const CFG_XQARGS: string = "xqueryExecutionArguments"; export class XQueryExecutionProvider { static async executeXQueryAsync(editor: vsc.TextEditor): Promise { // this disposable will be used for creating status bar messages let disposable: vsc.Disposable; - if (editor.document.languageId !== 'xquery') { - vsc.window.showErrorMessage('This action can only be performed on an XQuery file.'); + if (editor.document.languageId !== "xquery") { + vsc.window.showErrorMessage("This action can only be performed on an XQuery file."); return; } let executable = vsc.workspace.getConfiguration(CFG_SECTION).get(CFG_XQEXEC, null); let args = vsc.workspace.getConfiguration(CFG_SECTION).get(CFG_XQARGS, []); - if (!executable || executable == '') { - let action = await vsc.window.showWarningMessage('An XQuery execution engine has not been defined.', 'Define Now'); + if (!executable || executable == "") { + let action = await vsc.window.showWarningMessage("An XQuery execution engine has not been defined.", "Define Now"); - if (action == 'Define Now') { - vsc.commands.executeCommand('workbench.action.openGlobalSettings'); + if (action == "Define Now") { + vsc.commands.executeCommand("workbench.action.openGlobalSettings"); } return; } let inputFile: vsc.Uri; - disposable = vsc.window.setStatusBarMessage('Searching for XML files in folder...'); - let files: vsc.Uri[] = await vsc.workspace.findFiles('**/*.xml', '', 100); + disposable = vsc.window.setStatusBarMessage("Searching for XML files in folder..."); + let files: vsc.Uri[] = await vsc.workspace.findFiles("**/*.xml", "", 100); disposable.dispose(); // user does not have a folder open - prompt for file name - if (typeof files === 'undefined') { - vsc.window.showErrorMessage('You must have a folder opened in VS Code to use this feature.'); + if (typeof files === "undefined") { + vsc.window.showErrorMessage("You must have a folder opened in VS Code to use this feature."); return; } @@ -45,16 +45,16 @@ export class XQueryExecutionProvider { let qpItems: any[] = new Array(); files.forEach((file) => { - let filename: string = file.fsPath.replace('\\', '/'); + let filename: string = file.fsPath.replace("\\", "/"); qpItems.push({ // must implement vscode.QuickPickItem - label: filename.substring(filename.lastIndexOf('/') + 1), + label: filename.substring(filename.lastIndexOf("/") + 1), description: file.fsPath, file: file }); }); - let selection = await vsc.window.showQuickPick(qpItems, { placeHolder: 'Please select an input file.' }); + let selection = await vsc.window.showQuickPick(qpItems, { placeHolder: "Please select an input file." }); if (!selection) { return; @@ -82,8 +82,8 @@ export class XQueryExecutionProvider { if (outputPath) { outputPath = await vsc.window.showInputBox({ - placeHolder: 'ex. C:\\TEMP\XQueryOutput\\MyOutputFile.xml', - prompt: 'Please specify the output file path. Existing file behavior is determined by the execution engine you have specified.', + placeHolder: "ex. C:\\TEMP\XQueryOutput\\MyOutputFile.xml", + prompt: "Please specify the output file path. Existing file behavior is determined by the execution engine you have specified.", value: outputPath }); @@ -91,12 +91,12 @@ export class XQueryExecutionProvider { } // call out to the execution engine - disposable = vsc.window.setStatusBarMessage('Executing XQuery Script...'); + disposable = vsc.window.setStatusBarMessage("Executing XQuery Script..."); args = args.map((value: string) => { return value - .replace('$(script)', editor.document.uri.fsPath) - .replace('$(input)', inputFile.fsPath) - .replace('$(project)', vsc.workspace.rootPath); + .replace("$(script)", editor.document.uri.fsPath) + .replace("$(input)", inputFile.fsPath) + .replace("$(project)", vsc.workspace.rootPath); }); try { @@ -106,7 +106,7 @@ export class XQueryExecutionProvider { catch (error) { if (error.message.search(/[Ll]ine:?\s*\d+/gm) > -1) { let match: RegExpExecArray = /[Ll]ine:?\s*\d+/gm.exec(error.message); - let line: number = (Number.parseInt(match[0].replace(/([Ll]ine:?\s*)|\s/, '')) - 1); + let line: number = (Number.parseInt(match[0].replace(/([Ll]ine:?\s*)|\s/, "")) - 1); let selection: string = await vsc.window.showErrorMessage(error.message, `Go to Line ${line}`); diff --git a/src/providers/Formatting.ts b/src/providers/Formatting.ts index bd3a900..5bc3faf 100644 --- a/src/providers/Formatting.ts +++ b/src/providers/Formatting.ts @@ -1,9 +1,9 @@ -import * as vsc from 'vscode'; -import { RangeUtil } from '../utils/RangeUtil'; -import { XmlFormatter, IXmlFormatterOptions } from '../services/XmlFormatter'; +import * as vsc from "vscode"; +import { RangeUtil } from "../utils/RangeUtil"; +import { XmlFormatter, IXmlFormatterOptions } from "../services/XmlFormatter"; -const CFG_SECTION: string = 'xmlTools'; -const CFG_SPLIT_NAMESPACES: string = 'splitXmlnsOnFormat'; +const CFG_SECTION: string = "xmlTools"; +const CFG_SPLIT_NAMESPACES: string = "splitXmlnsOnFormat"; export class XmlFormattingEditProvider implements vsc.DocumentFormattingEditProvider, vsc.DocumentRangeFormattingEditProvider { provideDocumentFormattingEdits(document: vsc.TextDocument, options: vsc.FormattingOptions): vsc.TextEdit[] { diff --git a/src/providers/Linting.ts b/src/providers/Linting.ts index 3f8992a..2658554 100644 --- a/src/providers/Linting.ts +++ b/src/providers/Linting.ts @@ -1,12 +1,12 @@ -import * as vsc from 'vscode'; -import { XQueryLinter, XQueryDiagnostic } from '../services/XQueryLinter'; +import * as vsc from "vscode"; +import { XQueryLinter, XQueryDiagnostic } from "../services/XQueryLinter"; export class XQueryLintingFeatureProvider { private static _coreDiagnostics: vsc.DiagnosticCollection; static get coreDiagnostics(): vsc.DiagnosticCollection { if (!XQueryLintingFeatureProvider._coreDiagnostics) { - XQueryLintingFeatureProvider._coreDiagnostics = vsc.languages.createDiagnosticCollection('XQueryDiagnostics'); + XQueryLintingFeatureProvider._coreDiagnostics = vsc.languages.createDiagnosticCollection("XQueryDiagnostics"); } return XQueryLintingFeatureProvider._coreDiagnostics; diff --git a/src/providers/XPath.ts b/src/providers/XPath.ts index adca124..b5ddd5e 100644 --- a/src/providers/XPath.ts +++ b/src/providers/XPath.ts @@ -1,13 +1,13 @@ -import * as vsc from 'vscode'; -import * as ext from '../Extension'; -import { XPathEvaluator, EvaluatorResult, EvaluatorResultType } from '../services/XPathEvaluator'; +import * as vsc from "vscode"; +import * as ext from "../Extension"; +import { XPathEvaluator, EvaluatorResult, EvaluatorResultType } from "../services/XPathEvaluator"; -const CFG_SECTION: string = 'xmlTools'; -const CFG_PERSIST_QUERY: string = 'persistXPathQuery'; -const CFG_IGNORE_DEFAULT_XMLNS: string = 'ignoreDefaultNamespace'; -const MEM_QUERY_HISTORY: string = 'xpathQueryHistory'; -const MEM_QUERY_LAST: string = 'xPathQueryLast'; -const OUTPUT_CHANNEL: string = 'XPath Results'; +const CFG_SECTION: string = "xmlTools"; +const CFG_PERSIST_QUERY: string = "persistXPathQuery"; +const CFG_IGNORE_DEFAULT_XMLNS: string = "ignoreDefaultNamespace"; +const MEM_QUERY_HISTORY: string = "xpathQueryHistory"; +const MEM_QUERY_LAST: string = "xPathQueryLast"; +const OUTPUT_CHANNEL: string = "XPath Results"; export class XPathFeatureProvider { static async evaluateXPathAsync(editor: vsc.TextEditor, edit: vsc.TextEditorEdit): Promise { @@ -21,7 +21,7 @@ export class XPathFeatureProvider { // if not, try pulling the last query ran, regardless of document // NOTE: if the user has focus on the output channel when opening the xquery prompt, the channel is the "active" document let history: HistoricQuery[] = memento.get(MEM_QUERY_HISTORY, new Array()); - let globalLastQuery: string = memento.get(MEM_QUERY_LAST, ''); + let globalLastQuery: string = memento.get(MEM_QUERY_LAST, ""); let lastQuery: HistoricQuery = history.find((item: HistoricQuery) => { if (item.uri == editor.document.uri.toString()) { @@ -32,7 +32,7 @@ export class XPathFeatureProvider { }); // set the inital display value and prompt the user - let query: string = ''; + let query: string = ""; if (persistQueries) { if (lastQuery) { @@ -45,8 +45,8 @@ export class XPathFeatureProvider { } query = await vsc.window.showInputBox({ - placeHolder: 'XPath Query', - prompt: 'Please enter an XPath query to evaluate.', + placeHolder: "XPath Query", + prompt: "Please enter an XPath query to evaluate.", value: query }); @@ -73,7 +73,7 @@ export class XPathFeatureProvider { outputChannel.clear(); outputChannel.appendLine(`XPath Query: ${query}`); - outputChannel.append('\n'); + outputChannel.append("\n"); if (evalResult.type === EvaluatorResultType.NODE_COLLECTION) { (evalResult.result as Node[]).forEach((node: XmlNode) => { diff --git a/src/services/ChildProcess.ts b/src/services/ChildProcess.ts index 5af998e..53257eb 100644 --- a/src/services/ChildProcess.ts +++ b/src/services/ChildProcess.ts @@ -1,22 +1,22 @@ -let child_process = require('child_process'); +let child_process = require("child_process"); export class ChildProcess { static async spawnAsync(executable: string, args: string[]): Promise { return new Promise((resolve, reject) => { - let output: string = ''; + let output: string = ""; let handle = child_process.spawn(executable, args); - handle.stdout.on('data', (data: string) => { + handle.stdout.on("data", (data: string) => { output += data; }); - handle.stderr.on('data', (data: string) => { + handle.stderr.on("data", (data: string) => { output += data; }); - handle.on('close', (code: string) => { - if (code == '0') { + handle.on("close", (code: string) => { + if (code == "0") { resolve(); } diff --git a/src/services/XPathEvaluator.ts b/src/services/XPathEvaluator.ts index b7a1a54..c67ee58 100644 --- a/src/services/XPathEvaluator.ts +++ b/src/services/XPathEvaluator.ts @@ -1,6 +1,6 @@ -import * as xpath from 'xpath'; +import * as xpath from "xpath"; -let DOMParser = require('xmldom').DOMParser; +let DOMParser = require("xmldom").DOMParser; export class EvaluatorResult { type: EvaluatorResultType; @@ -16,13 +16,13 @@ export class XPathEvaluator { static evaluate(query: string, xml: string, ignoreDefaultNamespace: boolean): EvaluatorResult { if (ignoreDefaultNamespace) { xml = xml.replace(/xmlns=".+"/g, (match: string) => { - return match.replace(/xmlns/g, 'xmlns:default'); + return match.replace(/xmlns/g, "xmlns:default"); }); } let nodes: Node[] = new Array(); - let xdoc: Document = new DOMParser().parseFromString(xml, 'text/xml'); + let xdoc: Document = new DOMParser().parseFromString(xml, "text/xml"); let resolver: xpath.XPathNSResolver = xpath.createNSResolver(xdoc); let result: xpath.XPathResult = xpath.evaluate( diff --git a/src/services/XQueryCompleter.ts b/src/services/XQueryCompleter.ts index 8bc4467..463f864 100644 --- a/src/services/XQueryCompleter.ts +++ b/src/services/XQueryCompleter.ts @@ -1,4 +1,4 @@ -let XQLint = require('xqlint').XQLint; +let XQLint = require("xqlint").XQLint; export class XQueryCompleter { constructor(script: string) { diff --git a/src/services/XQueryLinter.ts b/src/services/XQueryLinter.ts index 30e5c8a..b893a0e 100644 --- a/src/services/XQueryLinter.ts +++ b/src/services/XQueryLinter.ts @@ -1,4 +1,4 @@ -let XQLint = require('xqlint').XQLint; +let XQLint = require("xqlint").XQLint; export class XQueryLinter { static SEVERITY_WARNING: number = 1; diff --git a/src/services/XmlFormatter.ts b/src/services/XmlFormatter.ts index 6cf6e72..f92692c 100644 --- a/src/services/XmlFormatter.ts +++ b/src/services/XmlFormatter.ts @@ -3,19 +3,19 @@ export class XmlFormatter { constructor(options?: IXmlFormatterOptions) { options = options || {}; - if (typeof options.preferSpaces === 'undefined') { + if (typeof options.preferSpaces === "undefined") { options.preferSpaces = false; } - if (typeof options.splitNamespaces === 'undefined') { + if (typeof options.splitNamespaces === "undefined") { options.splitNamespaces = true; } options.tabSize = options.tabSize || 4; - options.newLine = options.newLine || '\n'; + options.newLine = options.newLine || "\n"; - this.newLine = options.newLine || '\n'; - this.indentPattern = (options.preferSpaces) ? ' '.repeat(options.tabSize) : '\t'; + this.newLine = options.newLine || "\n"; + this.indentPattern = (options.preferSpaces) ? " ".repeat(options.tabSize) : "\t"; this.splitNamespaces = options.splitNamespaces; } @@ -25,19 +25,19 @@ export class XmlFormatter { format(xml: string): string { xml = this.minify(xml, false); - xml = xml.replace(/ else if (/^<(\w|:)/.test(parts[i - 1]) && /^<\/(\w|:)/.test(parts[i]) - && /^<[\w:\-\.\,\/]+/.exec(parts[i - 1])[0] == /^<\/[\w:\-\.\,]+/.exec(parts[i])[0].replace('/', '')) { + && /^<[\w:\-\.\,\/]+/.exec(parts[i - 1])[0] == /^<\/[\w:\-\.\,]+/.exec(parts[i])[0].replace("/", "")) { output += parts[i]; if (!inComment) level--; @@ -118,31 +118,31 @@ export class XmlFormatter { } minify(xml: string, removeComments?: boolean): string { - if (typeof removeComments === 'undefined') { + if (typeof removeComments === "undefined") { removeComments = false; } xml = this._stripLineBreaks(xml); // all line breaks outside of CDATA elements - xml = (removeComments) ? xml.replace(/\/g, '') : xml; - xml = xml.replace(/>\s{0,}<'); // insignificant whitespace between tags - xml = xml.replace(/"\s+(?=[^\s]+=)/g, '" '); // spaces between attributes - xml = xml.replace(/"\s+(?=>)/g, '"'); // spaces between the last attribute and tag close (>) - xml = xml.replace(/"\s+(?=\/>)/g, '" '); // spaces between the last attribute and tag close (/>) + xml = (removeComments) ? xml.replace(/\/g, "") : xml; + xml = xml.replace(/>\s{0,}<"); // insignificant whitespace between tags + xml = xml.replace(/"\s+(?=[^\s]+=)/g, "\" "); // spaces between attributes + xml = xml.replace(/"\s+(?=>)/g, "\""); // spaces between the last attribute and tag close (>) + xml = xml.replace(/"\s+(?=\/>)/g, "\" "); // spaces between the last attribute and tag close (/>) xml = xml.replace(/[^ <>="]\s+[^ <>="]+=/g, (match: string) => { // spaces between the node name and the first attribute - return match.replace(/\s+/g, ' '); + return match.replace(/\s+/g, " "); }); return xml; } private _getIndent(level: number, trailingValue?: string): string { - trailingValue = trailingValue || ''; + trailingValue = trailingValue || ""; return `${this.newLine}${this.indentPattern.repeat(level)}${trailingValue}`; } private _stripLineBreaks(xml: string): string { - let output: string = ''; + let output: string = ""; let inTag: boolean = false; let inTagName: boolean = false; let inCdata: boolean = false; @@ -153,15 +153,15 @@ export class XmlFormatter { let prev: string = xml.charAt(i - 1); let next: string = xml.charAt(i + 1); - if (char == '!' && (xml.substr(i, 8) == '![CDATA[' || xml.substr(i, 3) == '!--')) { + if (char == "!" && (xml.substr(i, 8) == "![CDATA[" || xml.substr(i, 3) == "!--")) { inCdata = true; } - else if (char == ']' && (xml.substr(i, 3) == ']]>')) { + else if (char == "]" && (xml.substr(i, 3) == "]]>")) { inCdata = false; } - else if (char == '-' && (xml.substr(i, 3) == '-->')) { + else if (char == "-" && (xml.substr(i, 3) == "-->")) { inCdata = false; } diff --git a/src/utils/RangeUtil.ts b/src/utils/RangeUtil.ts index ebb3dc6..b51b412 100644 --- a/src/utils/RangeUtil.ts +++ b/src/utils/RangeUtil.ts @@ -1,4 +1,4 @@ -import * as vsc from 'vscode'; +import * as vsc from "vscode"; export class RangeUtil { static getRangeForDocument(document: vsc.TextDocument): vsc.Range {