aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/ctx.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts30
1 files changed, 30 insertions, 0 deletions
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 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
3import { Server } from './server';
4
5
6export class Ctx {
7 private extCtx: vscode.ExtensionContext
8
9 constructor(extCtx: vscode.ExtensionContext) {
10 this.extCtx = extCtx
11 }
12
13 get client(): lc.LanguageClient {
14 return Server.client
15 }
16
17 registerCommand(
18 name: string,
19 factory: (ctx: Ctx) => () => Promise<vscode.TextEditor>,
20 ) {
21 const fullName = `rust-analyzer.${name}`
22 const cmd = factory(this);
23 const d = vscode.commands.registerCommand(fullName, cmd);
24 this.pushCleanup(d);
25 }
26
27 pushCleanup(d: { dispose(): any }) {
28 this.extCtx.subscriptions.push(d)
29 }
30}