2019-12-30 13:42:59 +00:00
|
|
|
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,
|
2019-12-30 13:53:43 +00:00
|
|
|
factory: (ctx: Ctx) => Cmd,
|
2019-12-30 13:42:59 +00:00
|
|
|
) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-12-30 13:53:43 +00:00
|
|
|
|
|
|
|
export type Cmd = (...args: any[]) => any;
|