diff options
author | Aleksey Kladov <[email protected]> | 2019-12-30 15:43:34 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-30 18:07:59 +0000 |
commit | 5aebf1081dced95a71c674aba65fb5b3e40e6ff1 (patch) | |
tree | bacedf66912eee5a366a3c93c60a39ba29744f92 /editors/code/src/ctx.ts | |
parent | 83d2527880d86653ce00940c65620319b36afcff (diff) |
Refactor applySourceChange
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 22 |
1 files changed, 22 insertions, 0 deletions
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 { | |||
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 | |||
30 | pushCleanup(d: { dispose(): any }) { | 52 | pushCleanup(d: { dispose(): any }) { |
31 | this.extCtx.subscriptions.push(d); | 53 | this.extCtx.subscriptions.push(d); |
32 | } | 54 | } |