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/extension.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'editors/code/src/extension.ts') diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 81e1107a0..3e5767535 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -15,6 +15,23 @@ export function activate(context: vscode.ExtensionContext) { function registerCommand(name: string, f: any) { disposeOnDeactivation(vscode.commands.registerCommand(name, f)); } + function overrideCommand( + + name: string, + f: (...args: any[]) => Promise, + ) { + const defaultCmd = `default:${name}`; + const original = async (...args: any[]) => await vscode.commands.executeCommand(defaultCmd, ...args); + registerCommand(name, async (...args: any[]) => { + const editor = vscode.window.activeTextEditor; + if (!editor || !editor.document || editor.document.languageId !== 'rust') { + return await original(...args); + } + if (!await f(...args)) { + return await original(...args); + } + }) + } // Commands are requests from vscode to the language server registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); @@ -27,11 +44,12 @@ export function activate(context: vscode.ExtensionContext) { 'ra-lsp.applySourceChange', commands.applySourceChange.handle ); + overrideCommand('type', commands.on_enter.handle) // Notifications are events triggered by the language server const allNotifications: Iterable< [string, lc.GenericNotificationHandler] - > = [['m/publishDecorations', notifications.publishDecorations.handle]]; + > = [['m/publishDecorations', notifications.publishDecorations.handle]]; // The events below are plain old javascript events, triggered and handled by vscode vscode.window.onDidChangeActiveTextEditor( -- cgit v1.2.3