From b12cbd60628b6061649c3d41bc8d7022c75aa362 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 24 Feb 2020 12:32:15 +0100 Subject: Don't break onEnter if rust-analyzer fails to start closes #3253 --- editors/code/src/main.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'editors') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 7b3bb6302..424ff1ac3 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -12,6 +12,26 @@ import { log } from './util'; let ctx: Ctx | undefined; export async function activate(context: vscode.ExtensionContext) { + // Register a "dumb" onEnter command for the case where server fails to + // start. + // + // FIXME: refactor command registration code such that commands are + // **always** registered, even if the server does not start. Use API like + // this perhaps? + // + // ```TypeScript + // registerCommand( + // factory: (Ctx) => ((Ctx) => any), + // fallback: () => any = () => vscode.window.showErrorMessage( + // "rust-analyzer is not available" + // ), + // ) + const defaultOnEnter = vscode.commands.registerCommand( + 'rust-analyzer.onEnter', + () => vscode.commands.executeCommand('default:type', { text: '\n' }), + ); + context.subscriptions.push(defaultOnEnter); + const config = new Config(context); const serverPath = await ensureServerBinary(config.serverSource); @@ -54,7 +74,10 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('syntaxTree', commands.syntaxTree); ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('run', commands.run); + + defaultOnEnter.dispose(); ctx.registerCommand('onEnter', commands.onEnter); + ctx.registerCommand('ssr', commands.ssr); ctx.registerCommand('serverVersion', commands.serverVersion); -- cgit v1.2.3