Skip to content

Commit b12cbd6

Browse files
committed
Don't break onEnter if rust-analyzer fails to start
closes #3253
1 parent 1d1c1b0 commit b12cbd6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

editors/code/src/main.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ import { log } from './util';
1212
let ctx: Ctx | undefined;
1313

1414
export async function activate(context: vscode.ExtensionContext) {
15+
// Register a "dumb" onEnter command for the case where server fails to
16+
// start.
17+
//
18+
// FIXME: refactor command registration code such that commands are
19+
// **always** registered, even if the server does not start. Use API like
20+
// this perhaps?
21+
//
22+
// ```TypeScript
23+
// registerCommand(
24+
// factory: (Ctx) => ((Ctx) => any),
25+
// fallback: () => any = () => vscode.window.showErrorMessage(
26+
// "rust-analyzer is not available"
27+
// ),
28+
// )
29+
const defaultOnEnter = vscode.commands.registerCommand(
30+
'rust-analyzer.onEnter',
31+
() => vscode.commands.executeCommand('default:type', { text: '\n' }),
32+
);
33+
context.subscriptions.push(defaultOnEnter);
34+
1535
const config = new Config(context);
1636

1737
const serverPath = await ensureServerBinary(config.serverSource);
@@ -54,7 +74,10 @@ export async function activate(context: vscode.ExtensionContext) {
5474
ctx.registerCommand('syntaxTree', commands.syntaxTree);
5575
ctx.registerCommand('expandMacro', commands.expandMacro);
5676
ctx.registerCommand('run', commands.run);
77+
78+
defaultOnEnter.dispose();
5779
ctx.registerCommand('onEnter', commands.onEnter);
80+
5881
ctx.registerCommand('ssr', commands.ssr);
5982
ctx.registerCommand('serverVersion', commands.serverVersion);
6083

0 commit comments

Comments
 (0)