(
reader: &mut BufReader<tokio::process::ChildStdout>,
deadline: tokio::time::Instant,
partial_message: bool,
timeouts: LspRefreshTimeouts,
)
| 490 | } |
| 491 | |
| 492 | async fn read_byte_until( |
| 493 | reader: &mut BufReader<tokio::process::ChildStdout>, |
| 494 | deadline: tokio::time::Instant, |
| 495 | partial_message: bool, |
| 496 | timeouts: LspRefreshTimeouts, |
| 497 | ) -> Result<Option<u8>> { |
| 498 | let now = tokio::time::Instant::now(); |
| 499 | if now >= deadline { |
| 500 | return if partial_message { |
| 501 | Err(refresh_timed_out(timeouts)) |
| 502 | } else { |
| 503 | Ok(None) |
| 504 | }; |
| 505 | } |
| 506 | let mut byte = [0_u8; 1]; |
| 507 | match tokio::time::timeout( |
| 508 | deadline.saturating_duration_since(now), |
| 509 | reader.read(&mut byte), |
| 510 | ) |
| 511 | .await |
| 512 | { |
| 513 | Ok(Ok(0)) if partial_message => Err(TraceDecayError::Config { |
| 514 | message: "LSP server closed before completing message header".to_string(), |
| 515 | }), |
| 516 | Ok(Ok(0)) => Ok(None), |
| 517 | Ok(Ok(_)) => Ok(Some(byte[0])), |
| 518 | Ok(Err(err)) => Err(TraceDecayError::Config { |
| 519 | message: format!("failed to read LSP header: {err}"), |
| 520 | }), |
| 521 | Err(_) if partial_message => Err(refresh_timed_out(timeouts)), |
| 522 | Err(_) => Ok(None), |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | fn file_uri(path: &Path) -> String { |
| 527 | let absolute = if path.is_absolute() { |
no test coverage detected