Add on-enter handler

Now, typing doc comments is much more pleasant
This commit is contained in:
Aleksey Kladov 2018-10-09 16:00:20 +03:00
parent 82447ecace
commit 2b956fd3a8
12 changed files with 630 additions and 401 deletions

View file

@ -2,6 +2,7 @@ import * as applySourceChange from './apply_source_change';
import * as extendSelection from './extend_selection';
import * as joinLines from './join_lines';
import * as matchingBrace from './matching_brace';
import * as on_enter from './on_enter';
import * as parentModule from './parent_module';
import * as runnables from './runnables';
import * as syntaxTree from './syntaxTree';
@ -13,5 +14,6 @@ export {
matchingBrace,
parentModule,
runnables,
syntaxTree
syntaxTree,
on_enter,
};

View file

@ -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<boolean> {
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<undefined | SourceChange>(
'm/onEnter',
request
);
if (!change) {
return false;
}
await applySourceChange(change);
return true
}