]> git.lizzy.rs Git - rust.git/blob - editors/code/src/commands/on_enter.ts
Merge #193
[rust.git] / editors / code / src / commands / on_enter.ts
1 import * as vscode from 'vscode';
2 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
9
10 export async function handle(event: { text: string }): Promise<boolean> {
11     const editor = vscode.window.activeTextEditor;
12     if (
13         editor == null ||
14         editor.document.languageId !== 'rust' ||
15         event.text !== '\n'
16     ) {
17         return false;
18     }
19     const request: lc.TextDocumentPositionParams = {
20         textDocument: { uri: editor.document.uri.toString() },
21         position: Server.client.code2ProtocolConverter.asPosition(
22             editor.selection.active
23         )
24     };
25     const change = await Server.client.sendRequest<undefined | SourceChange>(
26         'm/onEnter',
27         request
28     );
29     if (!change) {
30         return false;
31     }
32     await applySourceChange(change);
33     return true;
34 }