]> git.lizzy.rs Git - rust.git/blobdiff - editors/code/src/ctx.ts
Refactor applySourceChange
[rust.git] / editors / code / src / ctx.ts
index 712337fe71c582c92cf6d48220e6b8e44f56c530..22af5ef321a529baa22400e762c6b46f3ecb499d 100644 (file)
@@ -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);
     }