From 5aebf1081dced95a71c674aba65fb5b3e40e6ff1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 16:43:34 +0100 Subject: Refactor applySourceChange --- editors/code/src/ctx.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'editors/code/src/ctx.ts') diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 712337fe7..22af5ef32 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -27,6 +27,28 @@ export class Ctx { this.pushCleanup(d); } + overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) { + const defaultCmd = `default:${name}`; + const override = factory(this); + const original = (...args: any[]) => + vscode.commands.executeCommand(defaultCmd, ...args); + try { + const d = vscode.commands.registerCommand( + name, + async (...args: any[]) => { + if (!(await override(...args))) { + return await original(...args); + } + }, + ); + this.pushCleanup(d); + } catch (_) { + vscode.window.showWarningMessage( + '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', + ); + } + } + pushCleanup(d: { dispose(): any }) { this.extCtx.subscriptions.push(d); } -- cgit v1.2.3