(
graph: &PetCodeGraph,
symbol: &str,
json: bool,
)
| 497 | } |
| 498 | |
| 499 | fn execute_callers( |
| 500 | graph: &PetCodeGraph, |
| 501 | symbol: &str, |
| 502 | json: bool, |
| 503 | ) -> Result<String, Box<dyn std::error::Error>> { |
| 504 | let functions = graph.find_functions_by_name(symbol); |
| 505 | let mut output = String::new(); |
| 506 | |
| 507 | if json { |
| 508 | let mut results = Vec::new(); |
| 509 | for func in &functions { |
| 510 | for (caller, relation) in graph.get_callers(&func.id) { |
| 511 | results.push(serde_json::json!({ |
| 512 | "caller": caller.name, |
| 513 | "caller_file": caller.file_path, |
| 514 | "caller_line": relation.line_number, |
| 515 | "target": func.name, |
| 516 | })); |
| 517 | } |
| 518 | } |
| 519 | output = serde_json::to_string_pretty(&results)?; |
| 520 | } else { |
| 521 | for func in &functions { |
| 522 | let callers = graph.get_callers(&func.id); |
| 523 | if callers.is_empty() { |
| 524 | output.push_str(&format!("No callers for '{}'\n", func.name)); |
| 525 | } else { |
| 526 | output.push_str(&format!("Callers of '{}':\n", func.name)); |
| 527 | for (caller, relation) in callers { |
| 528 | output.push_str(&format!( |
| 529 | " {} ({}:{})\n", |
| 530 | caller.name, |
| 531 | caller.file_path.display(), |
| 532 | relation.line_number |
| 533 | )); |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | if functions.is_empty() { |
| 540 | if json { |
| 541 | output = "[]".to_string(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | Ok(output) |
| 546 | } |
| 547 | |
| 548 | fn execute_callees( |
| 549 | graph: &PetCodeGraph, |
no test coverage detected