about summary refs log tree commit diff
path: root/editors/code/src/ctx.ts
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2019-12-30 16:43:34 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2019-12-30 19:07:59 +0100
commit5aebf1081dced95a71c674aba65fb5b3e40e6ff1 (patch)
treebacedf66912eee5a366a3c93c60a39ba29744f92 /editors/code/src/ctx.ts
parent83d2527880d86653ce00940c65620319b36afcff (diff)
downloadrust-5aebf1081dced95a71c674aba65fb5b3e40e6ff1.tar.gz
rust-5aebf1081dced95a71c674aba65fb5b3e40e6ff1.zip
Refactor applySourceChange
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 712337fe71c..22af5ef321a 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);
     }