diff options
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/index.ts | 4 | ||||
-rw-r--r-- | editors/code/src/commands/on_enter.ts | 29 |
2 files changed, 32 insertions, 1 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 2496c7ff8..d78a64c3e 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -2,6 +2,7 @@ import * as applySourceChange from './apply_source_change'; | |||
2 | import * as extendSelection from './extend_selection'; | 2 | import * as extendSelection from './extend_selection'; |
3 | import * as joinLines from './join_lines'; | 3 | import * as joinLines from './join_lines'; |
4 | import * as matchingBrace from './matching_brace'; | 4 | import * as matchingBrace from './matching_brace'; |
5 | import * as on_enter from './on_enter'; | ||
5 | import * as parentModule from './parent_module'; | 6 | import * as parentModule from './parent_module'; |
6 | import * as runnables from './runnables'; | 7 | import * as runnables from './runnables'; |
7 | import * as syntaxTree from './syntaxTree'; | 8 | import * as syntaxTree from './syntaxTree'; |
@@ -13,5 +14,6 @@ export { | |||
13 | matchingBrace, | 14 | matchingBrace, |
14 | parentModule, | 15 | parentModule, |
15 | runnables, | 16 | runnables, |
16 | syntaxTree | 17 | syntaxTree, |
18 | on_enter, | ||
17 | }; | 19 | }; |
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts new file mode 100644 index 000000000..2666797fe --- /dev/null +++ b/editors/code/src/commands/on_enter.ts | |||
@@ -0,0 +1,29 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | import * as lc from 'vscode-languageclient'; | ||
3 | import { Server } from '../server'; | ||
4 | import { handle as applySourceChange, SourceChange } from './apply_source_change'; | ||
5 | |||
6 | interface OnEnterParams { | ||
7 | textDocument: lc.TextDocumentIdentifier; | ||
8 | position: lc.Position; | ||
9 | } | ||
10 | |||
11 | export async function handle(event: { text: string }): Promise<boolean> { | ||
12 | const editor = vscode.window.activeTextEditor; | ||
13 | if (editor == null || editor.document.languageId !== 'rust' || event.text !== '\n') { | ||
14 | return false; | ||
15 | } | ||
16 | const request: OnEnterParams = { | ||
17 | textDocument: { uri: editor.document.uri.toString() }, | ||
18 | position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active), | ||
19 | }; | ||
20 | const change = await Server.client.sendRequest<undefined | SourceChange>( | ||
21 | 'm/onEnter', | ||
22 | request | ||
23 | ); | ||
24 | if (!change) { | ||
25 | return false; | ||
26 | } | ||
27 | await applySourceChange(change); | ||
28 | return true | ||
29 | } | ||