diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index dab2d8da8f0..c5fe5b83a09 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs @@ -37,11 +37,9 @@ pub struct Threads { } impl Threads { - pub fn join(self) -> Result<()> { - match self.reader.join() { - Ok(r) => r?, - Err(_) => bail!("reader panicked"), - } + pub fn exit(self) -> Result<()> { + // We can't rely on stdin being closed + drop(self.reader); match self.writer.join() { Ok(r) => r, Err(_) => bail!("writer panicked"), diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index b0b70df5c88..6b1274a3b2a 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs @@ -54,7 +54,7 @@ fn main_inner() -> Result<()> { ra_lsp_server::main_loop(workspace_roots, opts, r, s) })?; log::info!("shutting down IO..."); - threads.join()?; + threads.exit()?; log::info!("... IO is down"); Ok(()) } diff --git a/editors/code/package.json b/editors/code/package.json index 1c8caaa60cb..a0454191a15 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 ef83c0b8b21..db67bc7e3a9 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