Sends a request and waits for the response.
(
&self,
method: impl Into<String>,
params: Option<serde_json::Value>,
)
| 585 | |
| 586 | /// Sends a request and waits for the response. |
| 587 | pub async fn send_request( |
| 588 | &self, |
| 589 | method: impl Into<String>, |
| 590 | params: Option<serde_json::Value>, |
| 591 | ) -> Result<serde_json::Value> { |
| 592 | let id = self.request_id.fetch_add(1, Ordering::SeqCst); |
| 593 | let method_str = method.into(); |
| 594 | |
| 595 | let message = create_request(id, method_str.clone(), params); |
| 596 | |
| 597 | let (tx, rx) = oneshot::channel(); |
| 598 | |
| 599 | { |
| 600 | let mut pending = self.pending_requests.write().await; |
| 601 | pending.insert(id, tx); |
| 602 | } |
| 603 | |
| 604 | { |
| 605 | let mut stdin = self.stdin.write().await; |
| 606 | write_message(&mut stdin, &message).await?; |
| 607 | } |
| 608 | |
| 609 | let response = timeout(Duration::from_secs(60), rx).await.map_err(|_| { |
| 610 | error!("LSP request timeout after 60s: {}", method_str); |
| 611 | anyhow!( |
| 612 | "LSP request timeout (60s): {}. The LSP server may not be responding.", |
| 613 | method_str |
| 614 | ) |
| 615 | })??; |
| 616 | |
| 617 | extract_result(response) |
| 618 | } |
| 619 | |
| 620 | /// Sends a notification (does not wait for a response). |
| 621 | pub async fn send_notification( |
no test coverage detected