1 import * as vscode from 'vscode';
2 import * as lc from 'vscode-languageclient';
3 import { Server } from './server';
6 private extCtx: vscode.ExtensionContext;
8 constructor(extCtx: vscode.ExtensionContext) {
12 get client(): lc.LanguageClient {
16 get activeRustEditor(): vscode.TextEditor | undefined {
17 const editor = vscode.window.activeTextEditor;
18 return editor && editor.document.languageId === 'rust'
23 registerCommand(name: string, factory: (ctx: Ctx) => Cmd) {
24 const fullName = `rust-analyzer.${name}`;
25 const cmd = factory(this);
26 const d = vscode.commands.registerCommand(fullName, cmd);
30 overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) {
31 const defaultCmd = `default:${name}`;
32 const override = factory(this);
33 const original = (...args: any[]) =>
34 vscode.commands.executeCommand(defaultCmd, ...args);
36 const d = vscode.commands.registerCommand(
38 async (...args: any[]) => {
39 if (!(await override(...args))) {
40 return await original(...args);
46 vscode.window.showWarningMessage(
47 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings',
52 pushCleanup(d: { dispose(): any }) {
53 this.extCtx.subscriptions.push(d);
57 export type Cmd = (...args: any[]) => any;