From 12f28f6276bbf1d1a19a553c7352bcb974361247 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Mon, 15 Apr 2019 21:41:27 +0200 Subject: Adds "restart server" command --- editors/code/package.json | 5 +++++ editors/code/src/extension.ts | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index 1c8caaa60..a0454191a 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -114,6 +114,11 @@ "command": "rust-analyzer.collectGarbage", "title": "Run garbage collection", "category": "Rust Analyzer" + }, + { + "command": "rust-analyzer.reload", + "title": "Restart server", + "category": "Rust Analyzer" } ], "keybindings": [ diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index ef83c0b8b..db67bc7e3 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -120,11 +120,16 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions ); + const startServer = () => Server.start(allNotifications); + const reloadCommand = () => reloadServer(startServer); + + vscode.commands.registerCommand('rust-analyzer.reload', reloadCommand); + // Executing `cargo watch` provides us with inline diagnostics on save interactivelyStartCargoWatch(context); // Start the language server, finally! - Server.start(allNotifications); + startServer(); } export function deactivate(): Thenable { @@ -133,3 +138,12 @@ export function deactivate(): Thenable { } return Server.client.stop(); } + + +async function reloadServer(startServer: () => void) { + if (Server.client != null) { + vscode.window.showInformationMessage('Reloading rust-analyzer...'); + await Server.client.stop(); + startServer(); + } +} \ No newline at end of file -- cgit v1.2.3