From acd7552698d374fbf95b08f55cf9eba3e4ff863d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 12 Aug 2018 21:47:27 +0300 Subject: Simplify --- crates/server/src/main.rs | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'crates/server/src/main.rs') diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 345bb6ac4..fe94e901e 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -78,6 +78,11 @@ fn main_inner() -> Result<()> { fn initialize(io: &mut Io) -> Result<()> { loop { match io.recv()? { + RawMsg::Notification(n) => + bail!("expected initialize request, got {:?}", n), + RawMsg::Response(res) => + bail!("expected initialize request, got {:?}", res), + RawMsg::Request(req) => { let mut req = Some(req); dispatch::handle_request::(&mut req, |_params, resp| { @@ -86,33 +91,22 @@ fn initialize(io: &mut Io) -> Result<()> { io.send(RawMsg::Response(resp)); Ok(()) })?; - match req { - None => { - match io.recv()? { - RawMsg::Notification(n) => { - if n.method != "initialized" { - bail!("expected initialized notification"); - } - } - _ => { - bail!("expected initialized notification"); - } + if let Some(req) = req { + bail!("expected initialize request, got {:?}", req) + } + match io.recv()? { + RawMsg::Notification(n) => { + if n.method != "initialized" { + bail!("expected initialized notification"); } - return initialized(io); - } - Some(req) => { - bail!("expected initialize request, got {:?}", req) } + _ => bail!("expected initialized notification"), } - } - RawMsg::Notification(n) => { - bail!("expected initialize request, got {:?}", n) - } - RawMsg::Response(res) => { - bail!("expected initialize request, got {:?}", res) + break; } } } + initialized(io) } enum Task { -- cgit v1.2.3