(event: &Value)
| 469 | } |
| 470 | |
| 471 | fn cursor_event_candidates(event: &Value) -> Vec<PathBuf> { |
| 472 | let mut candidates = Vec::new(); |
| 473 | let mut push_unique = |candidate: PathBuf| { |
| 474 | if !candidates.iter().any(|seen| seen == &candidate) { |
| 475 | candidates.push(candidate); |
| 476 | } |
| 477 | }; |
| 478 | if let Some(cwd) = cursor_event_cwd(event) { |
| 479 | push_unique(cwd); |
| 480 | } |
| 481 | if let Some(project_root) = crate::config::brand_env("PROJECT_ROOT") { |
| 482 | push_unique(PathBuf::from(project_root)); |
| 483 | } |
| 484 | if let Some(file_path) = event |
| 485 | .get("file_path") |
| 486 | .and_then(Value::as_str) |
| 487 | .filter(|s| !s.is_empty()) |
| 488 | { |
| 489 | let path = Path::new(file_path); |
| 490 | push_unique(path.parent().unwrap_or(path).to_path_buf()); |
| 491 | } |
| 492 | if let Some(transcript_path) = event |
| 493 | .get("transcript_path") |
| 494 | .and_then(Value::as_str) |
| 495 | .filter(|s| !s.is_empty()) |
| 496 | { |
| 497 | let path = Path::new(transcript_path); |
| 498 | push_unique(path.parent().unwrap_or(path).to_path_buf()); |
| 499 | } |
| 500 | if let Some(roots) = event.get("workspace_roots").and_then(Value::as_array) { |
| 501 | for root in roots { |
| 502 | if let Some(path) = root.as_str().filter(|s| !s.is_empty()) { |
| 503 | push_unique(PathBuf::from(path)); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | candidates |
| 508 | } |
| 509 | |
| 510 | fn cursor_event_cwd(event: &Value) -> Option<PathBuf> { |
| 511 | event |
no test coverage detected