aboutsummaryrefslogtreecommitdiff
path: root/crates/server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server')
-rw-r--r--crates/server/src/dispatch.rs13
-rw-r--r--crates/server/src/main.rs28
2 files changed, 18 insertions, 23 deletions
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<R, F>(req: &mut Option<RawRequest>, f: F) -> Result<()>
71 } 71 }
72} 72}
73 73
74pub fn expect_request<R: ClientRequest>(io: &mut Io, raw: RawRequest)
75 -> Result<Option<(R::Params, Responder<R>)>>
76{
77 let ret = match parse_request_as::<R>(raw)? {
78 Ok(x) => Some(x),
79 Err(raw) => {
80 unknown_method(io, raw)?;
81 None
82 }
83 };
84 Ok(ret)
85}
86
87fn parse_notification_as<N>(raw: RawNotification) -> Result<::std::result::Result<N::Params, RawNotification>> 74fn parse_notification_as<N>(raw: RawNotification) -> Result<::std::result::Result<N::Params, RawNotification>>
88 where 75 where
89 N: Notification, 76 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<()> {
79 loop { 79 loop {
80 match io.recv()? { 80 match io.recv()? {
81 RawMsg::Request(req) => { 81 RawMsg::Request(req) => {
82 if let Some((_params, resp)) = dispatch::expect_request::<req::Initialize>(io, req)? { 82 let mut req = Some(req);
83 dispatch::handle_request::<req::Initialize, _>(&mut req, |_params, resp| {
83 let res = req::InitializeResult { capabilities: caps::SERVER_CAPABILITIES }; 84 let res = req::InitializeResult { capabilities: caps::SERVER_CAPABILITIES };
84 let resp = resp.into_response(Ok(res))?; 85 let resp = resp.into_response(Ok(res))?;
85 io.send(RawMsg::Response(resp)); 86 io.send(RawMsg::Response(resp));
86 match io.recv()? { 87 Ok(())
87 RawMsg::Notification(n) => { 88 })?;
88 if n.method != "initialized" { 89 match req {
90 None => {
91 match io.recv()? {
92 RawMsg::Notification(n) => {
93 if n.method != "initialized" {
94 bail!("expected initialized notification");
95 }
96 }
97 _ => {
89 bail!("expected initialized notification"); 98 bail!("expected initialized notification");
90 } 99 }
91 } 100 }
92 _ => { 101 return initialized(io);
93 bail!("expected initialized notification"); 102 }
94 } 103 Some(req) => {
104 bail!("expected initialize request, got {:?}", req)
95 } 105 }
96 return initialized(io);
97 } 106 }
98 } 107 }
99 RawMsg::Notification(n) => { 108 RawMsg::Notification(n) => {
@@ -106,7 +115,6 @@ fn initialize(io: &mut Io) -> Result<()> {
106 } 115 }
107} 116}
108 117
109
110enum Task { 118enum Task {
111 Respond(RawResponse), 119 Respond(RawResponse),
112 Notify(RawNotification), 120 Notify(RawNotification),
@@ -301,7 +309,7 @@ fn update_file_notifications_on_threadpool(
301 } 309 }
302 match publish_decorations(world, uri) { 310 match publish_decorations(world, uri) {
303 Err(e) => { 311 Err(e) => {
304 error!("failed to compute decortions: {:?}", e) 312 error!("failed to compute decorations: {:?}", e)
305 } 313 }
306 Ok(params) => { 314 Ok(params) => {
307 let not = dispatch::send_notification::<req::PublishDecorations>(params); 315 let not = dispatch::send_notification::<req::PublishDecorations>(params);