diff options
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 712337fe7..c3a3583b5 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -27,6 +27,32 @@ export class Ctx { | |||
27 | this.pushCleanup(d); | 27 | this.pushCleanup(d); |
28 | } | 28 | } |
29 | 29 | ||
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); | ||
35 | try { | ||
36 | const d = vscode.commands.registerCommand( | ||
37 | name, | ||
38 | async (...args: any[]) => { | ||
39 | if (!(await override(...args))) { | ||
40 | return await original(...args); | ||
41 | } | ||
42 | }, | ||
43 | ); | ||
44 | this.pushCleanup(d); | ||
45 | } catch (_) { | ||
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', | ||
48 | ); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | get subscriptions(): { dispose(): any }[] { | ||
53 | return this.extCtx.subscriptions; | ||
54 | } | ||
55 | |||
30 | pushCleanup(d: { dispose(): any }) { | 56 | pushCleanup(d: { dispose(): any }) { |
31 | this.extCtx.subscriptions.push(d); | 57 | this.extCtx.subscriptions.push(d); |
32 | } | 58 | } |