diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-09 17:52:48 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-09 17:52:48 +0100 |
commit | 31c8ebb743572ef07ac4ca77ddd17eddbcf4b24c (patch) | |
tree | 7a817485cf24ffe6e2acbec607115569bf3d8ac8 /editors/code/src/extension.ts | |
parent | 14baf11bd41eb17cfee79fd7f9d068c4e785aa71 (diff) | |
parent | 2b956fd3a83313cee37ff179eae843bc88dd572a (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/extension.ts')
-rw-r--r-- | editors/code/src/extension.ts | 20 |
1 files changed, 19 insertions, 1 deletions
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) { | |||
15 | function registerCommand(name: string, f: any) { | 15 | function registerCommand(name: string, f: any) { |
16 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); | 16 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); |
17 | } | 17 | } |
18 | function overrideCommand( | ||
19 | |||
20 | name: string, | ||
21 | f: (...args: any[]) => Promise<boolean>, | ||
22 | ) { | ||
23 | const defaultCmd = `default:${name}`; | ||
24 | const original = async (...args: any[]) => await vscode.commands.executeCommand(defaultCmd, ...args); | ||
25 | registerCommand(name, async (...args: any[]) => { | ||
26 | const editor = vscode.window.activeTextEditor; | ||
27 | if (!editor || !editor.document || editor.document.languageId !== 'rust') { | ||
28 | return await original(...args); | ||
29 | } | ||
30 | if (!await f(...args)) { | ||
31 | return await original(...args); | ||
32 | } | ||
33 | }) | ||
34 | } | ||
18 | 35 | ||
19 | // Commands are requests from vscode to the language server | 36 | // Commands are requests from vscode to the language server |
20 | registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); | 37 | registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); |
@@ -27,11 +44,12 @@ export function activate(context: vscode.ExtensionContext) { | |||
27 | 'ra-lsp.applySourceChange', | 44 | 'ra-lsp.applySourceChange', |
28 | commands.applySourceChange.handle | 45 | commands.applySourceChange.handle |
29 | ); | 46 | ); |
47 | overrideCommand('type', commands.on_enter.handle) | ||
30 | 48 | ||
31 | // Notifications are events triggered by the language server | 49 | // Notifications are events triggered by the language server |
32 | const allNotifications: Iterable< | 50 | const allNotifications: Iterable< |
33 | [string, lc.GenericNotificationHandler] | 51 | [string, lc.GenericNotificationHandler] |
34 | > = [['m/publishDecorations', notifications.publishDecorations.handle]]; | 52 | > = [['m/publishDecorations', notifications.publishDecorations.handle]]; |
35 | 53 | ||
36 | // The events below are plain old javascript events, triggered and handled by vscode | 54 | // The events below are plain old javascript events, triggered and handled by vscode |
37 | vscode.window.onDidChangeActiveTextEditor( | 55 | vscode.window.onDidChangeActiveTextEditor( |