diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index ab22052d9..8f41937dc 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -225,27 +225,15 @@ fn main_loop_inner( | |||
225 | let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); | 225 | let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); |
226 | msg_sender.send(resp.into()).unwrap() | 226 | msg_sender.send(resp.into()).unwrap() |
227 | } | 227 | } |
228 | Err(req) => { | 228 | Err(req) => on_request( |
229 | match on_request( | 229 | state, |
230 | state, | 230 | pending_requests, |
231 | pending_requests, | 231 | pool, |
232 | pool, | 232 | &task_sender, |
233 | &task_sender, | 233 | msg_sender, |
234 | loop_start, | 234 | loop_start, |
235 | req, | 235 | req, |
236 | )? { | 236 | )?, |
237 | None => (), | ||
238 | Some(req) => { | ||
239 | log::error!("unknown request: {:?}", req); | ||
240 | let resp = RawResponse::err( | ||
241 | req.id, | ||
242 | ErrorCode::MethodNotFound as i32, | ||
243 | "unknown request".to_string(), | ||
244 | ); | ||
245 | msg_sender.send(resp.into()).unwrap() | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | } | 237 | } |
250 | } | 238 | } |
251 | RawMessage::Notification(not) => { | 239 | RawMessage::Notification(not) => { |
@@ -320,12 +308,20 @@ fn on_request( | |||
320 | pending_requests: &mut PendingRequests, | 308 | pending_requests: &mut PendingRequests, |
321 | pool: &ThreadPool, | 309 | pool: &ThreadPool, |
322 | sender: &Sender<Task>, | 310 | sender: &Sender<Task>, |
311 | msg_sender: &Sender<RawMessage>, | ||
323 | request_received: Instant, | 312 | request_received: Instant, |
324 | req: RawRequest, | 313 | req: RawRequest, |
325 | ) -> Result<Option<RawRequest>> { | 314 | ) -> Result<()> { |
326 | let method = req.method.clone(); | 315 | let mut pool_dispatcher = PoolDispatcher { |
327 | let mut pool_dispatcher = PoolDispatcher { req: Some(req), res: None, pool, world, sender }; | 316 | req: Some(req), |
328 | let req = pool_dispatcher | 317 | pool, |
318 | world, | ||
319 | sender, | ||
320 | msg_sender, | ||
321 | pending_requests, | ||
322 | request_received, | ||
323 | }; | ||
324 | pool_dispatcher | ||
329 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? | 325 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? |
330 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? | 326 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? |
331 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? | 327 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? |
@@ -355,13 +351,7 @@ fn on_request( | |||
355 | .on::<req::Formatting>(handlers::handle_formatting)? | 351 | .on::<req::Formatting>(handlers::handle_formatting)? |
356 | .on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)? | 352 | .on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)? |
357 | .finish(); | 353 | .finish(); |
358 | match req { | 354 | Ok(()) |
359 | Ok(id) => { | ||
360 | pending_requests.start(PendingRequest { id, method, received: request_received }); | ||
361 | Ok(None) | ||
362 | } | ||
363 | Err(req) => Ok(Some(req)), | ||
364 | } | ||
365 | } | 355 | } |
366 | 356 | ||
367 | fn on_notification( | 357 | fn on_notification( |
@@ -435,10 +425,12 @@ fn on_notification( | |||
435 | 425 | ||
436 | struct PoolDispatcher<'a> { | 426 | struct PoolDispatcher<'a> { |
437 | req: Option<RawRequest>, | 427 | req: Option<RawRequest>, |
438 | res: Option<u64>, | ||
439 | pool: &'a ThreadPool, | 428 | pool: &'a ThreadPool, |
440 | world: &'a mut ServerWorldState, | 429 | world: &'a mut ServerWorldState, |
430 | pending_requests: &'a mut PendingRequests, | ||
431 | msg_sender: &'a Sender<RawMessage>, | ||
441 | sender: &'a Sender<Task>, | 432 | sender: &'a Sender<Task>, |
433 | request_received: Instant, | ||
442 | } | 434 | } |
443 | 435 | ||
444 | impl<'a> PoolDispatcher<'a> { | 436 | impl<'a> PoolDispatcher<'a> { |
@@ -459,7 +451,11 @@ impl<'a> PoolDispatcher<'a> { | |||
459 | return Ok(self); | 451 | return Ok(self); |
460 | } | 452 | } |
461 | }; | 453 | }; |
462 | self.res = Some(id); | 454 | self.pending_requests.start(PendingRequest { |
455 | id, | ||
456 | method: R::METHOD.to_string(), | ||
457 | received: self.request_received, | ||
458 | }); | ||
463 | 459 | ||
464 | // Real time requests block user typing, so we should react quickly to them. | 460 | // Real time requests block user typing, so we should react quickly to them. |
465 | // Currently this means that we try to cancel background jobs if we don't have | 461 | // Currently this means that we try to cancel background jobs if we don't have |
@@ -483,11 +479,18 @@ impl<'a> PoolDispatcher<'a> { | |||
483 | Ok(self) | 479 | Ok(self) |
484 | } | 480 | } |
485 | 481 | ||
486 | fn finish(&mut self) -> std::result::Result<u64, RawRequest> { | 482 | fn finish(&mut self) { |
487 | match (self.res.take(), self.req.take()) { | 483 | match self.req.take() { |
488 | (Some(res), None) => Ok(res), | 484 | None => (), |
489 | (None, Some(req)) => Err(req), | 485 | Some(req) => { |
490 | _ => unreachable!(), | 486 | log::error!("unknown request: {:?}", req); |
487 | let resp = RawResponse::err( | ||
488 | req.id, | ||
489 | ErrorCode::MethodNotFound as i32, | ||
490 | "unknown request".to_string(), | ||
491 | ); | ||
492 | self.msg_sender.send(resp.into()).unwrap(); | ||
493 | } | ||
491 | } | 494 | } |
492 | } | 495 | } |
493 | } | 496 | } |