diff options
author | Kevin DeLorey <[email protected]> | 2020-02-09 16:25:47 +0000 |
---|---|---|
committer | Kevin DeLorey <[email protected]> | 2020-02-09 16:37:43 +0000 |
commit | a957c473fdb79880c39b73dc9e0c923093cf16ac (patch) | |
tree | f998b548f530ce604651e0e6af314ed2ec74b3b5 /editors/code/src/commands/on_enter.ts | |
parent | 22caf982b99c54058e2e9200aeea0e61cada284a (diff) | |
parent | 1b9b13b4b4a75b5531c3f046ce6bf72d681f2732 (diff) |
Merge branch 'master' into kdelorey/complete-trait-impl
Diffstat (limited to 'editors/code/src/commands/on_enter.ts')
-rw-r--r-- | editors/code/src/commands/on_enter.ts | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 6f61883cd..25eaebcbe 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts | |||
@@ -1,28 +1,35 @@ | |||
1 | import * as vscode from 'vscode'; | ||
1 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
2 | 3 | ||
3 | import { applySourceChange, SourceChange } from '../source_change'; | 4 | import { applySourceChange, SourceChange } from '../source_change'; |
4 | import { Cmd, Ctx } from '../ctx'; | 5 | import { Cmd, Ctx } from '../ctx'; |
5 | 6 | ||
6 | export function onEnter(ctx: Ctx): Cmd { | 7 | async function handleKeypress(ctx: Ctx) { |
7 | return async (event: { text: string }) => { | 8 | const editor = ctx.activeRustEditor; |
8 | const editor = ctx.activeRustEditor; | 9 | const client = ctx.client; |
9 | const client = ctx.client; | 10 | |
10 | if (!editor || event.text !== '\n') return false; | 11 | if (!editor || !client) return false; |
11 | if (!client) return false; | 12 | |
13 | const request: lc.TextDocumentPositionParams = { | ||
14 | textDocument: { uri: editor.document.uri.toString() }, | ||
15 | position: client.code2ProtocolConverter.asPosition( | ||
16 | editor.selection.active, | ||
17 | ), | ||
18 | }; | ||
19 | const change = await client.sendRequest<undefined | SourceChange>( | ||
20 | 'rust-analyzer/onEnter', | ||
21 | request, | ||
22 | ); | ||
23 | if (!change) return false; | ||
12 | 24 | ||
13 | const request: lc.TextDocumentPositionParams = { | 25 | await applySourceChange(ctx, change); |
14 | textDocument: { uri: editor.document.uri.toString() }, | 26 | return true; |
15 | position: client.code2ProtocolConverter.asPosition( | 27 | } |
16 | editor.selection.active, | 28 | |
17 | ), | 29 | export function onEnter(ctx: Ctx): Cmd { |
18 | }; | 30 | return async () => { |
19 | const change = await client.sendRequest<undefined | SourceChange>( | 31 | if (await handleKeypress(ctx)) return; |
20 | 'rust-analyzer/onEnter', | ||
21 | request, | ||
22 | ); | ||
23 | if (!change) return false; | ||
24 | 32 | ||
25 | await applySourceChange(ctx, change); | 33 | await vscode.commands.executeCommand('default:type', { text: '\n' }); |
26 | return true; | ||
27 | }; | 34 | }; |
28 | } | 35 | } |