From effc1eae8be338ea949058cc89c39950c25858c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 30 Dec 2018 23:02:26 +0300 Subject: migrate gen-lsp-server to new crossbeam --- Cargo.lock | 14 +++++++++++++- crates/gen_lsp_server/Cargo.toml | 2 +- crates/gen_lsp_server/src/lib.rs | 10 +++++----- crates/gen_lsp_server/src/stdio.rs | 10 +++++++--- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e962d352..7f3723f2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,17 @@ dependencies = [ "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-channel" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-deque" version = "0.2.0" @@ -355,7 +366,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "gen_lsp_server" version = "0.1.0" dependencies = [ - "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1544,6 +1555,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7b85741761b7f160bc5e7e0c14986ef685b7f8bf9b7ad081c60c604bb4649827" +"checksum crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "137bc235f622ffaa0428e3854e24acb53291fc0b3ff6fb2cb75a8be6fb02f06b" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2449aaa4ec7ef96e5fb24db16024b935df718e9ae1cec0a1e68feeca2efca7b8" diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index afeeb1513..2aee4ea16 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml @@ -13,4 +13,4 @@ log = "0.4.3" failure = "0.1.2" serde_json = "1.0.24" serde = { version = "1.0.83", features = ["derive"] } -crossbeam-channel = "0.2.4" +crossbeam-channel = "0.3.5" diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index 8779fbf0f..b20652928 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs @@ -95,7 +95,7 @@ pub fn run_server( server(params, &receiver, &sender)?; log::info!("lsp server waiting for exit notification"); match receiver.recv() { - Some(RawMessage::Notification(n)) => n + Ok(RawMessage::Notification(n)) => n .cast::() .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, m => bail!("unexpected message during shutdown: {:?}", m), @@ -109,7 +109,7 @@ pub fn handle_shutdown(req: RawRequest, sender: &Sender) -> Option() { Ok((id, ())) => { let resp = RawResponse::ok::(id, &()); - sender.send(RawMessage::Response(resp)); + let _ = sender.send(RawMessage::Response(resp)); None } Err(req) => Some(req), @@ -122,16 +122,16 @@ fn initialize( caps: ServerCapabilities, ) -> Result { let (id, params) = match receiver.recv() { - Some(RawMessage::Request(req)) => match req.cast::() { + Ok(RawMessage::Request(req)) => match req.cast::() { Err(req) => bail!("expected initialize request, got {:?}", req), Ok(req) => req, }, msg => bail!("expected initialize request, got {:?}", msg), }; let resp = RawResponse::ok::(id, &InitializeResult { capabilities: caps }); - sender.send(RawMessage::Response(resp)); + sender.send(RawMessage::Response(resp)).unwrap(); match receiver.recv() { - Some(RawMessage::Notification(n)) => { + Ok(RawMessage::Notification(n)) => { n.cast::() .map_err(|_| format_err!("expected initialized notification"))?; } diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index 35d8e46d0..5c8e33854 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs @@ -9,11 +9,13 @@ use failure::bail; use crate::{RawMessage, Result}; pub fn stdio_transport() -> (Receiver, Sender, Threads) { - let (writer_sender, mut writer_receiver) = bounded::(16); + let (writer_sender, writer_receiver) = bounded::(16); let writer = thread::spawn(move || { let stdout = stdout(); let mut stdout = stdout.lock(); - writer_receiver.try_for_each(|it| it.write(&mut stdout))?; + writer_receiver + .into_iter() + .try_for_each(|it| it.write(&mut stdout))?; Ok(()) }); let (reader_sender, reader_receiver) = bounded::(16); @@ -21,7 +23,9 @@ pub fn stdio_transport() -> (Receiver, Sender, Threads) let stdin = stdin(); let mut stdin = stdin.lock(); while let Some(msg) = RawMessage::read(&mut stdin)? { - reader_sender.send(msg); + if let Err(_) = reader_sender.send(msg) { + break; + } } Ok(()) }); -- cgit v1.2.3