From e53ccb6e99bb0e92ebea19f150c8fbf9b6958634 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 14:42:59 +0100 Subject: Start new ctx module --- editors/code/src/ctx.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 editors/code/src/ctx.ts (limited to 'editors/code/src/ctx.ts') diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts new file mode 100644 index 000000000..8581667b4 --- /dev/null +++ b/editors/code/src/ctx.ts @@ -0,0 +1,30 @@ +import * as vscode from 'vscode'; +import * as lc from 'vscode-languageclient'; +import { Server } from './server'; + + +export class Ctx { + private extCtx: vscode.ExtensionContext + + constructor(extCtx: vscode.ExtensionContext) { + this.extCtx = extCtx + } + + get client(): lc.LanguageClient { + return Server.client + } + + registerCommand( + name: string, + factory: (ctx: Ctx) => () => Promise, + ) { + const fullName = `rust-analyzer.${name}` + const cmd = factory(this); + const d = vscode.commands.registerCommand(fullName, cmd); + this.pushCleanup(d); + } + + pushCleanup(d: { dispose(): any }) { + this.extCtx.subscriptions.push(d) + } +} -- cgit v1.2.3