diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index dab2d8da8f0..5edfbc39cb4 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs @@ -5,6 +5,7 @@ use std::{ use crossbeam_channel::{bounded, Receiver, Sender}; use failure::bail; +use lsp_types::notification::Exit; use crate::{RawMessage, Result}; @@ -21,9 +22,18 @@ pub fn stdio_transport() -> (Receiver, Sender, Threads) let stdin = stdin(); let mut stdin = stdin.lock(); while let Some(msg) = RawMessage::read(&mut stdin)? { + let is_exit = match &msg { + RawMessage::Notification(n) => n.is::(), + _ => false, + }; + if let Err(_) = reader_sender.send(msg) { break; } + + if is_exit { + break; + } } 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..1073a36a03e 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,11 @@ 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(); + } +} diff --git a/editors/code/src/utils/terminateProcess.sh b/editors/code/src/utils/terminateProcess.sh old mode 100644 new mode 100755