diff options
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/stdio.rs | 10 |
3 files changed, 13 insertions, 9 deletions
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" | |||
13 | failure = "0.1.2" | 13 | failure = "0.1.2" |
14 | serde_json = "1.0.24" | 14 | serde_json = "1.0.24" |
15 | serde = { version = "1.0.83", features = ["derive"] } | 15 | serde = { version = "1.0.83", features = ["derive"] } |
16 | crossbeam-channel = "0.2.4" | 16 | 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( | |||
95 | server(params, &receiver, &sender)?; | 95 | server(params, &receiver, &sender)?; |
96 | log::info!("lsp server waiting for exit notification"); | 96 | log::info!("lsp server waiting for exit notification"); |
97 | match receiver.recv() { | 97 | match receiver.recv() { |
98 | Some(RawMessage::Notification(n)) => n | 98 | Ok(RawMessage::Notification(n)) => n |
99 | .cast::<Exit>() | 99 | .cast::<Exit>() |
100 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, | 100 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, |
101 | m => bail!("unexpected message during shutdown: {:?}", m), | 101 | m => bail!("unexpected message during shutdown: {:?}", m), |
@@ -109,7 +109,7 @@ pub fn handle_shutdown(req: RawRequest, sender: &Sender<RawMessage>) -> Option<R | |||
109 | match req.cast::<Shutdown>() { | 109 | match req.cast::<Shutdown>() { |
110 | Ok((id, ())) => { | 110 | Ok((id, ())) => { |
111 | let resp = RawResponse::ok::<Shutdown>(id, &()); | 111 | let resp = RawResponse::ok::<Shutdown>(id, &()); |
112 | sender.send(RawMessage::Response(resp)); | 112 | let _ = sender.send(RawMessage::Response(resp)); |
113 | None | 113 | None |
114 | } | 114 | } |
115 | Err(req) => Some(req), | 115 | Err(req) => Some(req), |
@@ -122,16 +122,16 @@ fn initialize( | |||
122 | caps: ServerCapabilities, | 122 | caps: ServerCapabilities, |
123 | ) -> Result<InitializeParams> { | 123 | ) -> Result<InitializeParams> { |
124 | let (id, params) = match receiver.recv() { | 124 | let (id, params) = match receiver.recv() { |
125 | Some(RawMessage::Request(req)) => match req.cast::<Initialize>() { | 125 | Ok(RawMessage::Request(req)) => match req.cast::<Initialize>() { |
126 | Err(req) => bail!("expected initialize request, got {:?}", req), | 126 | Err(req) => bail!("expected initialize request, got {:?}", req), |
127 | Ok(req) => req, | 127 | Ok(req) => req, |
128 | }, | 128 | }, |
129 | msg => bail!("expected initialize request, got {:?}", msg), | 129 | msg => bail!("expected initialize request, got {:?}", msg), |
130 | }; | 130 | }; |
131 | let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps }); | 131 | let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps }); |
132 | sender.send(RawMessage::Response(resp)); | 132 | sender.send(RawMessage::Response(resp)).unwrap(); |
133 | match receiver.recv() { | 133 | match receiver.recv() { |
134 | Some(RawMessage::Notification(n)) => { | 134 | Ok(RawMessage::Notification(n)) => { |
135 | n.cast::<Initialized>() | 135 | n.cast::<Initialized>() |
136 | .map_err(|_| format_err!("expected initialized notification"))?; | 136 | .map_err(|_| format_err!("expected initialized notification"))?; |
137 | } | 137 | } |
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; | |||
9 | use crate::{RawMessage, Result}; | 9 | use crate::{RawMessage, Result}; |
10 | 10 | ||
11 | pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { | 11 | pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { |
12 | let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16); | 12 | let (writer_sender, writer_receiver) = bounded::<RawMessage>(16); |
13 | let writer = thread::spawn(move || { | 13 | let writer = thread::spawn(move || { |
14 | let stdout = stdout(); | 14 | let stdout = stdout(); |
15 | let mut stdout = stdout.lock(); | 15 | let mut stdout = stdout.lock(); |
16 | writer_receiver.try_for_each(|it| it.write(&mut stdout))?; | 16 | writer_receiver |
17 | .into_iter() | ||
18 | .try_for_each(|it| it.write(&mut stdout))?; | ||
17 | Ok(()) | 19 | Ok(()) |
18 | }); | 20 | }); |
19 | let (reader_sender, reader_receiver) = bounded::<RawMessage>(16); | 21 | let (reader_sender, reader_receiver) = bounded::<RawMessage>(16); |
@@ -21,7 +23,9 @@ pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) | |||
21 | let stdin = stdin(); | 23 | let stdin = stdin(); |
22 | let mut stdin = stdin.lock(); | 24 | let mut stdin = stdin.lock(); |
23 | while let Some(msg) = RawMessage::read(&mut stdin)? { | 25 | while let Some(msg) = RawMessage::read(&mut stdin)? { |
24 | reader_sender.send(msg); | 26 | if let Err(_) = reader_sender.send(msg) { |
27 | break; | ||
28 | } | ||
25 | } | 29 | } |
26 | Ok(()) | 30 | Ok(()) |
27 | }); | 31 | }); |