From 58c3370819666b1caf23f6d06443d215be99e6d4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 12 Aug 2018 21:45:03 +0300 Subject: Simplify --- crates/server/src/dispatch.rs | 13 ------------- crates/server/src/main.rs | 28 ++++++++++++++++++---------- 2 files changed, 18 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/server/src/dispatch.rs b/crates/server/src/dispatch.rs index 369c56b64..381649859 100644 --- a/crates/server/src/dispatch.rs +++ b/crates/server/src/dispatch.rs @@ -71,19 +71,6 @@ pub fn handle_request(req: &mut Option, f: F) -> Result<()> } } -pub fn expect_request(io: &mut Io, raw: RawRequest) - -> Result)>> -{ - let ret = match parse_request_as::(raw)? { - Ok(x) => Some(x), - Err(raw) => { - unknown_method(io, raw)?; - None - } - }; - Ok(ret) -} - fn parse_notification_as(raw: RawNotification) -> Result<::std::result::Result> where N: Notification, diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index be63fea93..345bb6ac4 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -79,21 +79,30 @@ fn initialize(io: &mut Io) -> Result<()> { loop { match io.recv()? { RawMsg::Request(req) => { - if let Some((_params, resp)) = dispatch::expect_request::(io, req)? { + let mut req = Some(req); + dispatch::handle_request::(&mut req, |_params, resp| { let res = req::InitializeResult { capabilities: caps::SERVER_CAPABILITIES }; let resp = resp.into_response(Ok(res))?; io.send(RawMsg::Response(resp)); - match io.recv()? { - RawMsg::Notification(n) => { - if n.method != "initialized" { + Ok(()) + })?; + match req { + None => { + match io.recv()? { + RawMsg::Notification(n) => { + if n.method != "initialized" { + bail!("expected initialized notification"); + } + } + _ => { bail!("expected initialized notification"); } } - _ => { - bail!("expected initialized notification"); - } + return initialized(io); + } + Some(req) => { + bail!("expected initialize request, got {:?}", req) } - return initialized(io); } } RawMsg::Notification(n) => { @@ -106,7 +115,6 @@ fn initialize(io: &mut Io) -> Result<()> { } } - enum Task { Respond(RawResponse), Notify(RawNotification), @@ -301,7 +309,7 @@ fn update_file_notifications_on_threadpool( } match publish_decorations(world, uri) { Err(e) => { - error!("failed to compute decortions: {:?}", e) + error!("failed to compute decorations: {:?}", e) } Ok(params) => { let not = dispatch::send_notification::(params); -- cgit v1.2.3