Consolidate Constants
This commit is contained in:
parent
bce1b3dd87
commit
df45b80085
@ -2,7 +2,8 @@ export const extensionPrefix = "xmlTools";
|
|||||||
|
|
||||||
export namespace commands {
|
export namespace commands {
|
||||||
export const evaluateXPath = "xmlTools.evaluateXPath";
|
export const evaluateXPath = "xmlTools.evaluateXPath";
|
||||||
export const setContext = "setContext";
|
export const formatAsXml = "xmlTools.formatAsXml";
|
||||||
|
export const minifyXml = "xmlTools.minifyXml";
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace contextKeys {
|
export namespace contextKeys {
|
||||||
@ -13,9 +14,36 @@ export namespace configKeys {
|
|||||||
export const enableXmlTreeView = "enableXmlTreeView";
|
export const enableXmlTreeView = "enableXmlTreeView";
|
||||||
export const ignoreDefaultNamespace = "ignoreDefaultNamespace";
|
export const ignoreDefaultNamespace = "ignoreDefaultNamespace";
|
||||||
export const persistXPathQuery = "persistXPathQuery";
|
export const persistXPathQuery = "persistXPathQuery";
|
||||||
|
export const removeCommentsOnMinify = "removeCommentsOnMinify";
|
||||||
|
export const splitAttributesOnFormat = "splitAttributesOnFormat";
|
||||||
|
export const splitXmlnsOnFormat = "splitXmlnsOnFormat";
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace diagnosticCollections {
|
||||||
|
export const xquery = "XQueryDiagnostics";
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace languageIds {
|
||||||
|
export const xml = "xml";
|
||||||
|
export const xquery = "xquery";
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace nativeCommands {
|
||||||
|
export const cursorMove = "cursorMove";
|
||||||
|
export const revealLine = "revealLine";
|
||||||
|
export const setContext = "setContext";
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace stateKeys {
|
export namespace stateKeys {
|
||||||
export const xpathQueryHistory = "xpathQueryHistory";
|
export const xpathQueryHistory = "xpathQueryHistory";
|
||||||
export const xPathQueryLast = "xPathQueryLast";
|
export const xPathQueryLast = "xPathQueryLast";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace views {
|
||||||
|
export const xmlTreeView = "xmlTreeView";
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace xmlFormatterImplementations {
|
||||||
|
export const classic = "classic";
|
||||||
|
export const v2 = "v2";
|
||||||
|
}
|
||||||
|
@ -2,8 +2,8 @@ import { languages, window, workspace, commands } from "vscode";
|
|||||||
import { ExtensionContext, Memento, TextEditor, TextEditorSelectionChangeEvent, WorkspaceConfiguration } from "vscode";
|
import { ExtensionContext, Memento, TextEditor, TextEditorSelectionChangeEvent, WorkspaceConfiguration } from "vscode";
|
||||||
|
|
||||||
import { XQueryCompletionItemProvider } from "./completion/xquery-completion-item-provider";
|
import { XQueryCompletionItemProvider } from "./completion/xquery-completion-item-provider";
|
||||||
import { FormatAsXmlCommandName, formatAsXml } from "./formatting/commands/formatAsXml";
|
import { formatAsXml } from "./formatting/commands/formatAsXml";
|
||||||
import { MinifyXmlCommandName, minifyXml } from "./formatting/commands/minifyXml";
|
import { minifyXml } from "./formatting/commands/minifyXml";
|
||||||
import { XmlFormatterFactory } from "./formatting/xml-formatter";
|
import { XmlFormatterFactory } from "./formatting/xml-formatter";
|
||||||
import { XmlFormattingEditProvider } from "./formatting/xml-formatting-edit-provider";
|
import { XmlFormattingEditProvider } from "./formatting/xml-formatting-edit-provider";
|
||||||
import { XQueryLinter } from "./linting/xquery-linter";
|
import { XQueryLinter } from "./linting/xquery-linter";
|
||||||
@ -22,17 +22,17 @@ export function activate(context: ExtensionContext) {
|
|||||||
|
|
||||||
/* Completion Features */
|
/* Completion Features */
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
languages.registerCompletionItemProvider("xquery", new XQueryCompletionItemProvider(), ":", "$")
|
languages.registerCompletionItemProvider(constants.languageIds.xquery, new XQueryCompletionItemProvider(), ":", "$")
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Formatting Features */
|
/* Formatting Features */
|
||||||
const xmlFormattingEditProvider = new XmlFormattingEditProvider(config, XmlFormatterFactory.getXmlFormatter());
|
const xmlFormattingEditProvider = new XmlFormattingEditProvider(config, XmlFormatterFactory.getXmlFormatter());
|
||||||
|
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
commands.registerTextEditorCommand(FormatAsXmlCommandName, formatAsXml),
|
commands.registerTextEditorCommand(constants.commands.formatAsXml, formatAsXml),
|
||||||
commands.registerTextEditorCommand(MinifyXmlCommandName, minifyXml),
|
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
||||||
languages.registerDocumentFormattingEditProvider("xml", xmlFormattingEditProvider),
|
languages.registerDocumentFormattingEditProvider(constants.languageIds.xml, xmlFormattingEditProvider),
|
||||||
languages.registerDocumentRangeFormattingEditProvider("xml", xmlFormattingEditProvider)
|
languages.registerDocumentRangeFormattingEditProvider(constants.languageIds.xml, xmlFormattingEditProvider)
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Linting Features */
|
/* Linting Features */
|
||||||
@ -43,7 +43,7 @@ export function activate(context: ExtensionContext) {
|
|||||||
|
|
||||||
/* Tree View Features */
|
/* Tree View Features */
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
window.registerTreeDataProvider("xmlTreeView", new XmlTreeDataProvider(context))
|
window.registerTreeDataProvider(constants.views.xmlTreeView, new XmlTreeDataProvider(context))
|
||||||
);
|
);
|
||||||
|
|
||||||
/* XPath Features */
|
/* XPath Features */
|
||||||
@ -63,8 +63,10 @@ function _handleContextChange(editor: TextEditor): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (editor.document.languageId) {
|
switch (editor.document.languageId) {
|
||||||
case "xquery":
|
case constants.languageIds.xquery:
|
||||||
languages.createDiagnosticCollection("XQueryDiagnostics").set(editor.document.uri, new XQueryLinter().lint(editor.document.getText()));
|
languages
|
||||||
|
.createDiagnosticCollection(constants.diagnosticCollections.xquery)
|
||||||
|
.set(editor.document.uri, new XQueryLinter().lint(editor.document.getText()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import { XmlFormatterFactory } from "../xml-formatter";
|
|||||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||||
|
|
||||||
export const FormatAsXmlCommandName = "xmlTools.formatAsXml";
|
|
||||||
|
|
||||||
export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
|
export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
|
||||||
const xmlFormattingEditProvider = new XmlFormattingEditProvider(workspace.getConfiguration(constants.extensionPrefix), XmlFormatterFactory.getXmlFormatter());
|
const xmlFormattingEditProvider = new XmlFormattingEditProvider(workspace.getConfiguration(constants.extensionPrefix), XmlFormatterFactory.getXmlFormatter());
|
||||||
const formattingOptions = {
|
const formattingOptions = {
|
||||||
@ -40,11 +38,11 @@ export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
|
|||||||
editBuilder.replace(textEdit.range, textEdit.newText);
|
editBuilder.replace(textEdit.range, textEdit.newText);
|
||||||
|
|
||||||
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
|
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
|
||||||
await commands.executeCommand("cursorMove", {
|
await commands.executeCommand(constants.nativeCommands.cursorMove, {
|
||||||
to: "left",
|
to: "left",
|
||||||
by: "character"
|
by: "character"
|
||||||
});
|
});
|
||||||
await commands.executeCommand("cursorMove", {
|
await commands.executeCommand(constants.nativeCommands.cursorMove, {
|
||||||
to: "right",
|
to: "right",
|
||||||
by: "character"
|
by: "character"
|
||||||
});
|
});
|
||||||
|
@ -7,8 +7,6 @@ import { XmlFormatterFactory } from "../xml-formatter";
|
|||||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||||
|
|
||||||
export const MinifyXmlCommandName = "xmlTools.minifyXml";
|
|
||||||
|
|
||||||
export function minifyXml(editor: TextEditor, edit: TextEditorEdit): void {
|
export function minifyXml(editor: TextEditor, edit: TextEditorEdit): void {
|
||||||
const xmlFormatter = XmlFormatterFactory.getXmlFormatter();
|
const xmlFormatter = XmlFormatterFactory.getXmlFormatter();
|
||||||
const xmlFormattingOptions = XmlFormattingOptionsFactory.getXmlFormattingOptions({
|
const xmlFormattingOptions = XmlFormattingOptionsFactory.getXmlFormattingOptions({
|
||||||
|
@ -23,8 +23,9 @@ export class XmlFormatterFactory {
|
|||||||
let xmlFormatterImplementation: XmlFormatter;
|
let xmlFormatterImplementation: XmlFormatter;
|
||||||
|
|
||||||
switch (xmlFormatterImplementationSetting) {
|
switch (xmlFormatterImplementationSetting) {
|
||||||
case "classic": xmlFormatterImplementation = new ClassicXmlFormatter(); break;
|
case constants.xmlFormatterImplementations.classic: xmlFormatterImplementation = new ClassicXmlFormatter(); break;
|
||||||
case "v2": default: xmlFormatterImplementation = new V2XmlFormatter(); break;
|
case constants.xmlFormatterImplementations.v2:
|
||||||
|
default: xmlFormatterImplementation = new V2XmlFormatter(); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (XmlFormatterFactory._xmlFormatter = xmlFormatterImplementation);
|
return (XmlFormatterFactory._xmlFormatter = xmlFormatterImplementation);
|
||||||
|
@ -18,9 +18,9 @@ export class XmlFormattingOptionsFactory {
|
|||||||
return {
|
return {
|
||||||
editorOptions: formattingOptions,
|
editorOptions: formattingOptions,
|
||||||
newLine: (eol === EndOfLine.CRLF) ? "\r\n" : "\n",
|
newLine: (eol === EndOfLine.CRLF) ? "\r\n" : "\n",
|
||||||
removeCommentsOnMinify: config.get<boolean>("removeCommentsOnMinify"),
|
removeCommentsOnMinify: config.get<boolean>(constants.configKeys.removeCommentsOnMinify),
|
||||||
splitAttributesOnFormat: config.get<boolean>("splitAttributesOnFormat"),
|
splitAttributesOnFormat: config.get<boolean>(constants.configKeys.splitAttributesOnFormat),
|
||||||
splitXmlnsOnFormat: config.get<boolean>("splitXmlnsOnFormat")
|
splitXmlnsOnFormat: config.get<boolean>(constants.configKeys.splitXmlnsOnFormat)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
treeItem.command = {
|
treeItem.command = {
|
||||||
command: "revealLine",
|
command: constants.nativeCommands.revealLine,
|
||||||
title: "",
|
title: "",
|
||||||
arguments: [{
|
arguments: [{
|
||||||
lineNumber: element.lineNumber - 1,
|
lineNumber: element.lineNumber - 1,
|
||||||
@ -120,8 +120,8 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _refreshTree(): void {
|
private _refreshTree(): void {
|
||||||
if (!this.activeEditor || this.activeEditor.document.languageId !== "xml") {
|
if (!this.activeEditor || this.activeEditor.document.languageId !== constants.languageIds.xml) {
|
||||||
commands.executeCommand(constants.commands.setContext, constants.contextKeys.xmlTreeViewEnabled, false);
|
commands.executeCommand(constants.nativeCommands.setContext, constants.contextKeys.xmlTreeViewEnabled, false);
|
||||||
|
|
||||||
this._xmlDocument = null;
|
this._xmlDocument = null;
|
||||||
this._onDidChangeTreeData.fire();
|
this._onDidChangeTreeData.fire();
|
||||||
@ -131,7 +131,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||||||
const config = workspace.getConfiguration(constants.extensionPrefix);
|
const config = workspace.getConfiguration(constants.extensionPrefix);
|
||||||
const enableTreeView = config.get<boolean>(constants.configKeys.enableXmlTreeView, true);
|
const enableTreeView = config.get<boolean>(constants.configKeys.enableXmlTreeView, true);
|
||||||
|
|
||||||
commands.executeCommand(constants.commands.setContext, constants.contextKeys.xmlTreeViewEnabled, enableTreeView);
|
commands.executeCommand(constants.nativeCommands.setContext, constants.contextKeys.xmlTreeViewEnabled, enableTreeView);
|
||||||
|
|
||||||
const xml = this.activeEditor.document.getText();
|
const xml = this.activeEditor.document.getText();
|
||||||
this._xmlDocument = new DOMParser().parseFromString(xml, "text/xml");
|
this._xmlDocument = new DOMParser().parseFromString(xml, "text/xml");
|
||||||
|
Loading…
Reference in New Issue
Block a user