2018-02-13 23:25:07 -05:00
|
|
|
import { languages, window, workspace } from "vscode";
|
|
|
|
import { ExtensionContext, TextEditor, TextEditorSelectionChangeEvent, WorkspaceConfiguration } from "vscode";
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
import { XmlFormatter } from "./formatting/xml-formatter";
|
|
|
|
import { XmlFormattingEditProvider } from "./formatting/xml-formatting-edit-provider";
|
|
|
|
import { ClassicXmlFormatter } from "./formatting/formatters/classic-xml-formatter";
|
|
|
|
import { V2XmlFormatter } from "./formatting/formatters/v2-xml-formatter";
|
2018-02-13 23:25:07 -05:00
|
|
|
import { XQueryLinter } from "./linting/xquery-linter";
|
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
|
|
|
|
|
|
|
export function activate(context: ExtensionContext) {
|
2018-01-28 01:19:06 -05:00
|
|
|
const config = workspace.getConfiguration(constants.extensionPrefix);
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
/* Formatting Features */
|
|
|
|
const xmlFormatterImplementationSetting = config.get<string>("xmlFormatterImplementation");
|
|
|
|
let xmlFormatterImplementation: XmlFormatter;
|
2018-01-27 17:50:50 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
switch (xmlFormatterImplementationSetting) {
|
|
|
|
case "v2": xmlFormatterImplementation = new V2XmlFormatter(); break;
|
|
|
|
case "classic": default: xmlFormatterImplementation = new ClassicXmlFormatter(); break;
|
|
|
|
}
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
const xmlFormattingEditProvider = new XmlFormattingEditProvider(config, xmlFormatterImplementation);
|
2018-01-27 20:30:03 -05:00
|
|
|
|
2018-01-28 01:19:06 -05:00
|
|
|
context.subscriptions.push(
|
|
|
|
languages.registerDocumentFormattingEditProvider("xml", xmlFormattingEditProvider),
|
|
|
|
languages.registerDocumentRangeFormattingEditProvider("xml", xmlFormattingEditProvider)
|
|
|
|
);
|
2018-02-13 23:25:07 -05:00
|
|
|
|
|
|
|
/* Linting Features */
|
|
|
|
context.subscriptions.push(
|
|
|
|
window.onDidChangeActiveTextEditor(_handleChangeActiveTextEditor),
|
|
|
|
window.onDidChangeTextEditorSelection(_handleChangeTextEditorSelection)
|
|
|
|
);
|
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 {
|
|
|
|
if (!editor || !editor.document) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-13 23:30:01 -05:00
|
|
|
|
2018-02-13 23:25:07 -05:00
|
|
|
switch (editor.document.languageId) {
|
|
|
|
case "xquery":
|
|
|
|
languages.createDiagnosticCollection("XQueryDiagnostics").set(editor.document.uri, new XQueryLinter().lint(editor.document.getText()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleChangeActiveTextEditor(editor: TextEditor): void {
|
|
|
|
_handleContextChange(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleChangeTextEditorSelection(e: TextEditorSelectionChangeEvent): void {
|
|
|
|
_handleContextChange(e.textEditor);
|
|
|
|
}
|