From 2b956fd3a83313cee37ff179eae843bc88dd572a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Oct 2018 16:00:20 +0300 Subject: Add on-enter handler Now, typing doc comments is much more pleasant --- editors/code/src/commands/on_enter.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 editors/code/src/commands/on_enter.ts (limited to 'editors/code/src/commands/on_enter.ts') 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 @@ +import * as vscode from 'vscode'; +import * as lc from 'vscode-languageclient'; +import { Server } from '../server'; +import { handle as applySourceChange, SourceChange } from './apply_source_change'; + +interface OnEnterParams { + textDocument: lc.TextDocumentIdentifier; + position: lc.Position; +} + +export async function handle(event: { text: string }): Promise { + const editor = vscode.window.activeTextEditor; + if (editor == null || editor.document.languageId !== 'rust' || event.text !== '\n') { + return false; + } + const request: OnEnterParams = { + textDocument: { uri: editor.document.uri.toString() }, + position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active), + }; + const change = await Server.client.sendRequest( + 'm/onEnter', + request + ); + if (!change) { + return false; + } + await applySourceChange(change); + return true +} -- cgit v1.2.3