2016-01-06 15:55:11 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import * as vsc from 'vscode';
|
|
|
|
import { TextEditorCommands } from './Commands';
|
2016-01-08 09:19:27 -05:00
|
|
|
import { XmlFormattingEditProvider } from './providers/Formatting';
|
2016-01-08 10:44:46 -05:00
|
|
|
import { XQueryLintingFeatureProvider } from './providers/Linting';
|
|
|
|
import { XQueryCompletionItemProvider } from './providers/Completion';
|
2016-02-16 18:42:23 -05:00
|
|
|
import { XmlTreeDocumentContentProvider } from './providers/Content';
|
2016-01-06 15:55:11 -05:00
|
|
|
|
|
|
|
export var GlobalState: vsc.Memento;
|
|
|
|
export var WorkspaceState: vsc.Memento;
|
|
|
|
|
|
|
|
const LANG_XML: string = 'xml';
|
2016-01-08 10:44:46 -05:00
|
|
|
const LANG_XQUERY: string = 'xquery;'
|
2016-01-07 11:19:29 -05:00
|
|
|
const MEM_QUERY_HISTORY: string = 'xpathQueryHistory';
|
2016-01-06 15:55:11 -05:00
|
|
|
|
|
|
|
export function activate(ctx: vsc.ExtensionContext) {
|
2016-01-18 15:59:58 -05:00
|
|
|
console.log('activate extension');
|
2016-01-06 15:55:11 -05:00
|
|
|
// 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),
|
2016-01-08 12:35:50 -05:00
|
|
|
vsc.commands.registerTextEditorCommand('xmlTools.evaluateXPath', TextEditorCommands.evaluateXPath),
|
2016-02-16 18:42:23 -05:00
|
|
|
vsc.commands.registerTextEditorCommand('xmlTools.executeXQuery', TextEditorCommands.executeXQuery),
|
2016-02-16 18:42:43 -05:00
|
|
|
vsc.commands.registerTextEditorCommand('xmlTools.viewXmlTree', TextEditorCommands.viewXmlTree)
|
2016-01-06 15:55:11 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// register language feature providers
|
|
|
|
ctx.subscriptions.push(
|
2016-01-08 09:19:27 -05:00
|
|
|
vsc.languages.registerDocumentFormattingEditProvider(LANG_XML, new XmlFormattingEditProvider()),
|
2016-01-08 10:44:46 -05:00
|
|
|
vsc.languages.registerDocumentRangeFormattingEditProvider(LANG_XML, new XmlFormattingEditProvider()),
|
|
|
|
|
|
|
|
vsc.languages.registerCompletionItemProvider(LANG_XQUERY, new XQueryCompletionItemProvider(), ':', '$')
|
|
|
|
);
|
|
|
|
|
2016-02-16 18:42:23 -05:00
|
|
|
// register workspace feature providers
|
|
|
|
ctx.subscriptions.push(
|
|
|
|
vsc.workspace.registerTextDocumentContentProvider(XmlTreeDocumentContentProvider.SCHEME, new XmlTreeDocumentContentProvider())
|
|
|
|
);
|
|
|
|
|
2016-01-08 10:44:46 -05:00
|
|
|
// listen to editor events (for linting)
|
|
|
|
ctx.subscriptions.push(
|
|
|
|
vsc.window.onDidChangeActiveTextEditor(_handleChangeActiveTextEditor),
|
|
|
|
vsc.window.onDidChangeTextEditorSelection(_handleChangeTextEditorSelection)
|
2016-01-06 15:55:11 -05:00
|
|
|
);
|
2016-01-07 11:19:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function deactivate() {
|
|
|
|
// clean up xpath history
|
|
|
|
let memento: vsc.Memento = WorkspaceState || GlobalState;
|
|
|
|
let history = memento.get<any[]>(MEM_QUERY_HISTORY, []);
|
|
|
|
history.splice(0);
|
|
|
|
memento.update(MEM_QUERY_HISTORY, history);
|
2016-01-08 10:44:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function _handleContextChange(editor: vsc.TextEditor): void {
|
2016-01-08 21:50:30 -05:00
|
|
|
if (!editor || !editor.document) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-08 10:44:46 -05:00
|
|
|
switch (editor.document.languageId) {
|
|
|
|
case 'xquery':
|
|
|
|
XQueryLintingFeatureProvider.provideXQueryDiagnostics(editor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleChangeActiveTextEditor(editor: vsc.TextEditor): void {
|
|
|
|
_handleContextChange(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _handleChangeTextEditorSelection(e: vsc.TextEditorSelectionChangeEvent): void {
|
|
|
|
_handleContextChange(e.textEditor);
|
2016-01-06 15:55:11 -05:00
|
|
|
}
|