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 --- crates/gen_lsp_server/src/stdio.rs | 8 +++----- crates/ra_lsp_server/src/main.rs | 2 +- editors/code/package.json | 5 +++++ editors/code/src/extension.ts | 16 +++++++++++++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index dab2d8da8..c5fe5b83a 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 b0b70df5c..6b1274a3b 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 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 From 3bdd6973d176abe833477e4dfea9b268af57a99e Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Tue, 16 Apr 2019 22:06:27 +0200 Subject: Fixes unrelated process termination quirk --- editors/code/src/utils/terminateProcess.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 editors/code/src/utils/terminateProcess.sh diff --git a/editors/code/src/utils/terminateProcess.sh b/editors/code/src/utils/terminateProcess.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From 145ee9c3e9e81821053c33363f0ec3c0397d909d Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Tue, 16 Apr 2019 22:11:50 +0200 Subject: Prettier --- editors/code/src/extension.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index db67bc7e3..1073a36a0 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -139,11 +139,10 @@ 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 From 13d92b3f11246dc2d9a26b7d06ad8ebbcb96c47d Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Tue, 16 Apr 2019 22:25:17 +0200 Subject: Fixes doctest --- crates/gen_lsp_server/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index edbdda6c8..86b72f663 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs @@ -22,7 +22,7 @@ //! sender, //! main_loop, //! )?; -//! io_threads.join()?; +//! io_threads.exit()?; //! Ok(()) //! } //! -- cgit v1.2.3 From 8d569d49d2508cd7b50dd3d00d5509d4128bf645 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Wed, 17 Apr 2019 00:32:33 +0200 Subject: Breaks read loop on 'exit' --- crates/gen_lsp_server/src/lib.rs | 2 +- crates/gen_lsp_server/src/stdio.rs | 18 +++++++++++++++--- crates/ra_lsp_server/src/main.rs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index 86b72f663..edbdda6c8 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs @@ -22,7 +22,7 @@ //! sender, //! main_loop, //! )?; -//! io_threads.exit()?; +//! io_threads.join()?; //! Ok(()) //! } //! diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index c5fe5b83a..5edfbc39c 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(()) }); @@ -37,9 +47,11 @@ pub struct Threads { } impl Threads { - pub fn exit(self) -> Result<()> { - // We can't rely on stdin being closed - drop(self.reader); + pub fn join(self) -> Result<()> { + match self.reader.join() { + Ok(r) => r?, + Err(_) => bail!("reader panicked"), + } 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 6b1274a3b..b0b70df5c 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.exit()?; + threads.join()?; log::info!("... IO is down"); Ok(()) } -- cgit v1.2.3