2018-03-01 21:22:53 -05:00
|
|
|
import { languages, window, workspace, commands } from "vscode";
|
2018-04-28 00:10:51 -04:00
|
|
|
import { ExtensionContext, Memento, TextEditor, TextEditorSelectionChangeEvent, WorkspaceConfiguration } from "vscode";
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-04-28 21:15:20 -04:00
|
|
|
import { createDocumentSelector } from "./common/create-document-selector";
|
2018-03-01 21:50:18 -05:00
|
|
|
import { XQueryCompletionItemProvider } from "./completion/xquery-completion-item-provider";
|
2018-04-28 20:08:28 -04:00
|
|
|
import { formatAsXml } from "./formatting/commands/formatAsXml";
|
|
|
|
import { minifyXml } from "./formatting/commands/minifyXml";
|
2018-03-01 21:22:53 -05:00
|
|
|
import { XmlFormatterFactory } from "./formatting/xml-formatter";
|
2018-01-28 01:19:06 -05:00
|
|
|
import { XmlFormattingEditProvider } from "./formatting/xml-formatting-edit-provider";
|
2018-02-13 23:25:07 -05:00
|
|
|
import { XQueryLinter } from "./linting/xquery-linter";
|
2018-04-27 23:10:55 -04:00
|
|
|
import { XmlTreeDataProvider } from "./tree-view/xml-tree-data-provider";
|
2018-04-28 00:10:51 -04:00
|
|
|
import { evaluateXPath } from "./xpath/commands/evaluateXPath";
|
2018-04-28 20:36:58 -04:00
|
|
|
import { executeXQuery } from "./xquery-execution/commands/executeXQuery";
|
2018-01-27 20:51:15 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
import * as constants from "./constants";
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-04-28 00:10:51 -04:00
|
|
|
export const ExtensionState: { global?: Memento, workspace?: Memento } = { };
|
|
|
|
|
2018-01-27 20:30:03 -05:00
|
|
|
export function activate(context: ExtensionContext) {
|
2018-04-28 00:10:51 -04:00
|
|
|
ExtensionState.global = context.globalState;
|
|
|
|
ExtensionState.workspace = context.workspaceState;
|
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
const config = workspace.getConfiguration(constants.extensionPrefix);
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-04-28 21:15:20 -04:00
|
|
|
const xmlXsdDocSelector = [...createDocumentSelector(constants.languageIds.xml), ...createDocumentSelector(constants.languageIds.xsd)];
|
|
|
|
const xqueryDocSelector = createDocumentSelector(constants.languageIds.xquery);
|
|
|
|
|
2018-03-01 21:50:18 -05:00
|
|
|
/* Completion Features */
|
|
|
|
context.subscriptions.push(
|
2018-04-28 21:15:20 -04:00
|
|
|
languages.registerCompletionItemProvider(xqueryDocSelector, new XQueryCompletionItemProvider(), ":", "$")
|
2018-03-01 21:50:18 -05:00
|
|
|
);
|
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
/* Formatting Features */
|
2018-03-01 21:22:53 -05:00
|
|
|
const xmlFormattingEditProvider = new XmlFormattingEditProvider(config, XmlFormatterFactory.getXmlFormatter());
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
context.subscriptions.push(
|
2018-04-28 20:08:28 -04:00
|
|
|
commands.registerTextEditorCommand(constants.commands.formatAsXml, formatAsXml),
|
|
|
|
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
2018-04-28 21:15:20 -04:00
|
|
|
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
|
|
|
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
|
2018-01-28 01:19:06 -05:00
|
|
|
);
|
2018-02-13 23:25:07 -05:00
|
|
|
|
|
|
|
/* Linting Features */
|
|
|
|
context.subscriptions.push(
|
|
|
|
window.onDidChangeActiveTextEditor(_handleChangeActiveTextEditor),
|
|
|
|
window.onDidChangeTextEditorSelection(_handleChangeTextEditorSelection)
|
|
|
|
);
|
2018-04-27 23:10:55 -04:00
|
|
|
|
|
|
|
/* Tree View Features */
|
|
|
|
context.subscriptions.push(
|
2018-04-28 20:08:28 -04:00
|
|
|
window.registerTreeDataProvider(constants.views.xmlTreeView, new XmlTreeDataProvider(context))
|
2018-04-27 23:10:55 -04:00
|
|
|
);
|
2018-04-28 00:10:51 -04:00
|
|
|
|
|
|
|
/* XPath Features */
|
|
|
|
context.subscriptions.push(
|
|
|
|
commands.registerTextEditorCommand(constants.commands.evaluateXPath, evaluateXPath)
|
|
|
|
);
|
2018-04-28 20:36:58 -04:00
|
|
|
|
|
|
|
/* XQuery Features */
|
|
|
|
context.subscriptions.push(
|
|
|
|
commands.registerTextEditorCommand(constants.commands.executeXQuery, executeXQuery)
|
|
|
|
);
|
2018-01-27 20:30:03 -05:00
|
|
|
}
|
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
export function deactivate() {
|
|
|
|
// do nothing
|
|
|
|
}
|
2018-02-13 23:25:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
function _handleContextChange(editor: TextEditor): void {
|
2018-04-28 21:15:20 -04:00
|
|
|
const supportedSchemes = [constants.uriSchemes.file, constants.uriSchemes.untitled];
|
|
|
|
|
|
|
|
if (!editor || !editor.document || supportedSchemes.indexOf(editor.document.uri.scheme) === -1) {
|
2018-02-13 23:25:07 -05:00
|
|
|
return;
|
|
|
|
}
|
2018-02-13 23:30:01 -05:00
|
|
|
|
2018-02-13 23:25:07 -05:00
|
|
|
switch (editor.document.languageId) {
|
2018-04-28 20:08:28 -04:00
|
|
|
case constants.languageIds.xquery:
|
|
|
|
languages
|
|
|
|
.createDiagnosticCollection(constants.diagnosticCollections.xquery)
|
|
|
|
.set(editor.document.uri, new XQueryLinter().lint(editor.document.getText()));
|
2018-02-13 23:25:07 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleChangeActiveTextEditor(editor: TextEditor): void {
|
|
|
|
_handleContextChange(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleChangeTextEditorSelection(e: TextEditorSelectionChangeEvent): void {
|
|
|
|
_handleContextChange(e.textEditor);
|
|
|
|
}
|