(&self, method: &str, params: Value)
| 277 | } |
| 278 | |
| 279 | pub async fn request(&self, method: &str, params: Value) -> Result<Value, LspError> { |
| 280 | let id = self.next_id().await; |
| 281 | let (tx, rx) = tokio::sync::oneshot::channel(); |
| 282 | |
| 283 | self.pending_responses.write().await.insert(id, tx); |
| 284 | |
| 285 | let request = JsonRpcRequest { |
| 286 | jsonrpc: "2.0".to_string(), |
| 287 | id, |
| 288 | method: method.to_string(), |
| 289 | params, |
| 290 | }; |
| 291 | |
| 292 | let content = serde_json::to_string(&request)?; |
| 293 | let message = format!("Content-Length: {}\r\n\r\n{}", content.len(), content); |
| 294 | |
| 295 | let mut stdin = self.stdin.lock().await; |
| 296 | stdin.write_all(message.as_bytes()).await?; |
| 297 | stdin.flush().await?; |
| 298 | |
| 299 | rx.await.map_err(|_| LspError::Timeout)? |
| 300 | } |
| 301 | |
| 302 | pub async fn notify(&self, method: &str, params: Value) -> Result<(), LspError> { |
| 303 | let notification = JsonRpcNotification { |
no test coverage detected