diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-04 09:52:57 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-04 09:52:57 +0000 |
commit | c1a06499fa5f9a40750cbfc30a7d399228a5fab0 (patch) | |
tree | 9f2a049a5d9e49c55f41fd27b1a264d051f044c9 /editors/code/src/ctx.ts | |
parent | 73c36fdbd2060bd455ffeef33dca1ecc2ae07ebb (diff) | |
parent | 875dc6d1a4973f70cd48b797ae755d1bd7a83fa5 (diff) |
Merge #2981
2981: vscode: Add ability to call onEnter without overriding "type". r=matklad a=71
Before this PR, the only way to get enhanced typing (right now, only with `onEnter`) was to override VS Code's `type` command. This leads to issues with extensions like [VsCodeVim](https://github.com/VSCodeVim/Vim) that need to override `type` as well.
This PR adds an additional command, `onEnter`. This command can be used with the following keybinding, which allows the user to get smart `onEnter` behavior without overriding `type`.
```json
{
"key": "enter",
"command": "rust-analyzer.onEnter",
"when": "editorTextFocus && editorLangId == rust"
}
```
Co-authored-by: Gregoire Geis <[email protected]>
Co-authored-by: Grégoire Geis <[email protected]>
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 24 |
1 files changed, 0 insertions, 24 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 05d21ae56..aa75943bf 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -50,30 +50,6 @@ export class Ctx { | |||
50 | this.pushCleanup(d); | 50 | this.pushCleanup(d); |
51 | } | 51 | } |
52 | 52 | ||
53 | overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) { | ||
54 | const defaultCmd = `default:${name}`; | ||
55 | const override = factory(this); | ||
56 | const original = (...args: unknown[]) => | ||
57 | vscode.commands.executeCommand(defaultCmd, ...args); | ||
58 | try { | ||
59 | const d = vscode.commands.registerCommand( | ||
60 | name, | ||
61 | async (...args: unknown[]) => { | ||
62 | if (!(await override(...args))) { | ||
63 | return await original(...args); | ||
64 | } | ||
65 | }, | ||
66 | ); | ||
67 | this.pushCleanup(d); | ||
68 | } catch (_) { | ||
69 | vscode.window.showWarningMessage( | ||
70 | 'Enhanced typing feature is disabled because of incompatibility ' + | ||
71 | 'with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: ' + | ||
72 | 'https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings', | ||
73 | ); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | get subscriptions(): Disposable[] { | 53 | get subscriptions(): Disposable[] { |
78 | return this.extCtx.subscriptions; | 54 | return this.extCtx.subscriptions; |
79 | } | 55 | } |