diff --git a/src/common/extension-state.ts b/src/common/extension-state.ts new file mode 100644 index 0000000..c4fb213 --- /dev/null +++ b/src/common/extension-state.ts @@ -0,0 +1,17 @@ +import { ExtensionContext, Memento } from "vscode"; + +export class ExtensionState { + private static _context: ExtensionContext; + + static get global(): Memento { + return this._context.globalState; + } + + static get workspace(): Memento { + return this._context.workspaceState; + } + + static configure(context: ExtensionContext): void { + this._context = context; + } +} diff --git a/src/common/index.ts b/src/common/index.ts index 6a9e980..b322d14 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1 +1,2 @@ export * from "./create-document-selector"; +export * from "./extension-state"; diff --git a/src/extension.ts b/src/extension.ts index 265594f..2cad6cf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,7 @@ import { TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind } from "vscode"; -import { createDocumentSelector } from "./common"; +import { createDocumentSelector, ExtensionState } from "./common"; import { XQueryCompletionItemProvider } from "./completion"; import { XmlFormatterFactory, XmlFormattingEditProvider } from "./formatting"; import { formatAsXml, minifyXml } from "./formatting/commands"; @@ -14,11 +14,8 @@ import { executeXQuery } from "./xquery-execution/commands"; import * as constants from "./constants"; -export const ExtensionState: { global?: Memento, workspace?: Memento } = { }; - export function activate(context: ExtensionContext) { - ExtensionState.global = context.globalState; - ExtensionState.workspace = context.workspaceState; + ExtensionState.configure(context); const config = workspace.getConfiguration(constants.extensionPrefix); diff --git a/src/xpath/commands/evaluateXPath.ts b/src/xpath/commands/evaluateXPath.ts index 8f78a11..a22d10a 100644 --- a/src/xpath/commands/evaluateXPath.ts +++ b/src/xpath/commands/evaluateXPath.ts @@ -1,8 +1,8 @@ import { window, workspace } from "vscode"; import { TextEditor, TextEditorEdit, ViewColumn } from "vscode"; +import { ExtensionState } from "../../common"; import * as constants from "../../constants"; -import { ExtensionState } from "../../extension"; import { EvaluatorResult, EvaluatorResultType, XPathEvaluator } from "../xpath-evaluator";