aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/on_enter.ts
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-30 18:08:23 +0000
committerGitHub <[email protected]>2019-12-30 18:08:23 +0000
commit7c1634a9c2d76ea8c152c368775391090d62db8f (patch)
tree3879a92160f2313f54e738812d698d62e298f1a0 /editors/code/src/commands/on_enter.ts
parentb42d3ee3cc22aaa892d15c4ba2219a3bc53907a1 (diff)
parent260df66b7742e76c76184388253552c5055b1945 (diff)
Merge #2691
2691: Cleanup imports r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/commands/on_enter.ts')
-rw-r--r--editors/code/src/commands/on_enter.ts51
1 files changed, 22 insertions, 29 deletions
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts
index 772c64b3c..8324060e8 100644
--- a/editors/code/src/commands/on_enter.ts
+++ b/editors/code/src/commands/on_enter.ts
@@ -1,33 +1,26 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 1import * as lc from 'vscode-languageclient';
3import { Server } from '../server';
4import {
5 handle as applySourceChange,
6 SourceChange,
7} from './apply_source_change';
8 2
9export async function handle(event: { text: string }): Promise<boolean> { 3import { applySourceChange, SourceChange } from '../source_change';
10 const editor = vscode.window.activeTextEditor; 4import { Cmd, Ctx } from '../ctx';
11 if ( 5
12 editor == null || 6export 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 if (!editor || event.text !== '\n') return false;
16 return false; 10
17 } 11 const request: lc.TextDocumentPositionParams = {
18 const request: lc.TextDocumentPositionParams = { 12 textDocument: { uri: editor.document.uri.toString() },
19 textDocument: { uri: editor.document.uri.toString() }, 13 position: ctx.client.code2ProtocolConverter.asPosition(
20 position: Server.client.code2ProtocolConverter.asPosition( 14 editor.selection.active,
21 editor.selection.active, 15 ),
22 ), 16 };
17 const change = await ctx.client.sendRequest<undefined | SourceChange>(
18 'rust-analyzer/onEnter',
19 request,
20 );
21 if (!change) return false;
22
23 await applySourceChange(ctx, change);
24 return true;
23 }; 25 };
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} 26}