aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/on_enter.ts
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-09 17:52:48 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-09 17:52:48 +0100
commit31c8ebb743572ef07ac4ca77ddd17eddbcf4b24c (patch)
tree7a817485cf24ffe6e2acbec607115569bf3d8ac8 /editors/code/src/commands/on_enter.ts
parent14baf11bd41eb17cfee79fd7f9d068c4e785aa71 (diff)
parent2b956fd3a83313cee37ff179eae843bc88dd572a (diff)
Merge #106
106: Add on-enter handler r=matklad a=matklad Now, typing doc comments is much more pleasant 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.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts
new file mode 100644
index 000000000..2666797fe
--- /dev/null
+++ b/editors/code/src/commands/on_enter.ts
@@ -0,0 +1,29 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
3import { Server } from '../server';
4import { handle as applySourceChange, SourceChange } from './apply_source_change';
5
6interface OnEnterParams {
7 textDocument: lc.TextDocumentIdentifier;
8 position: lc.Position;
9}
10
11export async function handle(event: { text: string }): Promise<boolean> {
12 const editor = vscode.window.activeTextEditor;
13 if (editor == null || editor.document.languageId !== 'rust' || event.text !== '\n') {
14 return false;
15 }
16 const request: OnEnterParams = {
17 textDocument: { uri: editor.document.uri.toString() },
18 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active),
19 };
20 const change = await Server.client.sendRequest<undefined | SourceChange>(
21 'm/onEnter',
22 request
23 );
24 if (!change) {
25 return false;
26 }
27 await applySourceChange(change);
28 return true
29}