From 5aebf1081dced95a71c674aba65fb5b3e40e6ff1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 16:43:34 +0100 Subject: Refactor applySourceChange --- editors/code/src/main.ts | 52 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 42 deletions(-) (limited to 'editors/code/src/main.ts') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 95beb2d8f..c3f280630 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -27,44 +27,12 @@ export async 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 = (...args: any[]) => - vscode.commands.executeCommand(defaultCmd, ...args); - - try { - 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); - } - }); - } catch (_) { - vscode.window.showWarningMessage( - 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings', - ); - } - } // Commands are requests from vscode to the language server registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); registerCommand('rust-analyzer.run', commands.runnables.handle); // Unlike the above this does not send requests to the language server registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); - registerCommand( - 'rust-analyzer.applySourceChange', - commands.applySourceChange.handle, - ); registerCommand( 'rust-analyzer.showReferences', (uri: string, position: lc.Position, locations: lc.Location[]) => { @@ -78,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext) { ); if (Server.config.enableEnhancedTyping) { - overrideCommand('type', commands.onEnter.handle); + ctx.overrideCommand('type', commands.onEnter); } const watchStatus = new StatusDisplay( @@ -91,15 +59,15 @@ export async function activate(context: vscode.ExtensionContext) { string, lc.GenericNotificationHandler, ]> = [ - [ - 'rust-analyzer/publishDecorations', - notifications.publishDecorations.handle, - ], - [ - '$/progress', - params => watchStatus.handleProgressNotification(params), - ], - ]; + [ + 'rust-analyzer/publishDecorations', + notifications.publishDecorations.handle, + ], + [ + '$/progress', + params => watchStatus.handleProgressNotification(params), + ], + ]; const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); const expandMacroContentProvider = new ExpandMacroContentProvider(); -- cgit v1.2.3