Format match results into context content
(&self, file_match: &FileMatch, depth: &crate::context::ContextDepth)
| 258 | |
| 259 | /// Format match results into context content |
| 260 | fn format_match(&self, file_match: &FileMatch, depth: &crate::context::ContextDepth) -> String { |
| 261 | let mut output = String::new(); |
| 262 | let path_str = file_match.path.display().to_string(); |
| 263 | |
| 264 | match depth { |
| 265 | crate::context::ContextDepth::Abstract => { |
| 266 | // Just show file path and match count |
| 267 | output.push_str(&format!( |
| 268 | "{}: {} matches\n", |
| 269 | path_str, |
| 270 | file_match.matches.len() |
| 271 | )); |
| 272 | } |
| 273 | crate::context::ContextDepth::Overview => { |
| 274 | // Show first few matches with limited context |
| 275 | output.push_str(&format!("{}:\n", path_str)); |
| 276 | for (idx, m) in file_match.matches.iter().take(3).enumerate() { |
| 277 | if idx > 0 { |
| 278 | output.push('\n'); |
| 279 | } |
| 280 | output.push_str(&format!(" Line {}:\n", m.line_number)); |
| 281 | output.push_str(&format!(" {}\n", m.line_content)); |
| 282 | } |
| 283 | if file_match.matches.len() > 3 { |
| 284 | output.push_str(&format!( |
| 285 | " ... and {} more matches\n", |
| 286 | file_match.matches.len() - 3 |
| 287 | )); |
| 288 | } |
| 289 | } |
| 290 | crate::context::ContextDepth::Full => { |
| 291 | // Show all matches with full context |
| 292 | output.push_str(&format!("{}:\n", path_str)); |
| 293 | for (idx, m) in file_match.matches.iter().enumerate() { |
| 294 | if idx > 0 { |
| 295 | output.push('\n'); |
| 296 | } |
| 297 | output.push_str(&format!(" Line {}:\n", m.line_number)); |
| 298 | for ctx in &m.context_before { |
| 299 | output.push_str(&format!(" {}\n", ctx)); |
| 300 | } |
| 301 | output.push_str(&format!(" > {}\n", m.line_content)); |
| 302 | for ctx in &m.context_after { |
| 303 | output.push_str(&format!(" {}\n", ctx)); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | output |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | #[async_trait] |