diff options
Diffstat (limited to 'editors/code/src/commands/on_enter.ts')
-rw-r--r-- | editors/code/src/commands/on_enter.ts | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 772c64b3c..6f61883cd 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts | |||
@@ -1,33 +1,28 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | import * as lc from 'vscode-languageclient'; | 1 | import * as lc from 'vscode-languageclient'; |
3 | import { Server } from '../server'; | ||
4 | import { | ||
5 | handle as applySourceChange, | ||
6 | SourceChange, | ||
7 | } from './apply_source_change'; | ||
8 | 2 | ||
9 | export async function handle(event: { text: string }): Promise<boolean> { | 3 | import { applySourceChange, SourceChange } from '../source_change'; |
10 | const editor = vscode.window.activeTextEditor; | 4 | import { Cmd, Ctx } from '../ctx'; |
11 | if ( | 5 | |
12 | editor == null || | 6 | export function onEnter(ctx: Ctx): Cmd { |
13 | editor.document.languageId !== 'rust' || | 7 | return async (event: { text: string }) => { |
14 | event.text !== '\n' | 8 | const editor = ctx.activeRustEditor; |
15 | ) { | 9 | const client = ctx.client; |
16 | return false; | 10 | if (!editor || event.text !== '\n') return false; |
17 | } | 11 | if (!client) return false; |
18 | const request: lc.TextDocumentPositionParams = { | 12 | |
19 | textDocument: { uri: editor.document.uri.toString() }, | 13 | const request: lc.TextDocumentPositionParams = { |
20 | position: Server.client.code2ProtocolConverter.asPosition( | 14 | textDocument: { uri: editor.document.uri.toString() }, |
21 | editor.selection.active, | 15 | position: client.code2ProtocolConverter.asPosition( |
22 | ), | 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; | ||
24 | |||
25 | await applySourceChange(ctx, change); | ||
26 | return true; | ||
23 | }; | 27 | }; |
24 | const change = await Server.client.sendRequest<undefined | SourceChange>( | ||
25 | 'rust-analyzer/onEnter', | ||
26 | request, | ||
27 | ); | ||
28 | if (!change) { | ||
29 | return false; | ||
30 | } | ||
31 | await applySourceChange(change); | ||
32 | return true; | ||
33 | } | 28 | } |