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