MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_file_outline

Function build_file_outline

atomic-repository/src/ai/tools.rs:1069–1130  ·  view source on GitHub ↗

Build a structured outline of a large file instead of returning all content. For markdown: extracts headings with line numbers. For code: extracts function/class signatures using simple heuristics. Always includes the first 20 lines as context.

(path: &str, content: &str, total_lines: usize)

Source from the content-addressed store, hash-verified

1067/// For code: extracts function/class signatures using simple heuristics.
1068/// Always includes the first 20 lines as context.
1069fn build_file_outline(path: &str, content: &str, total_lines: usize) -> String {
1070 let mut out = format!(
1071 "File: {} ({} lines, {} bytes)\n\
1072 Use read_file with start_line/end_line to read specific sections.\n\n",
1073 path,
1074 total_lines,
1075 content.len()
1076 );
1077
1078 let is_markdown = path.ends_with(".md") || path.ends_with(".mdx");
1079
1080 if is_markdown {
1081 // Extract headings with line numbers
1082 out.push_str("Outline (headings):\n");
1083 for (i, line) in content.lines().enumerate() {
1084 let trimmed = line.trim();
1085 if trimmed.starts_with('#') {
1086 out.push_str(&format!(" L{}: {}\n", i + 1, trimmed));
1087 }
1088 }
1089 } else {
1090 // For code files, show the first 30 lines + any lines that look like
1091 // definitions (fn, class, struct, def, func, impl, etc.)
1092 out.push_str("First 20 lines:\n");
1093 for (i, line) in content.lines().take(20).enumerate() {
1094 out.push_str(&format!(" {:>4}: {}\n", i + 1, line));
1095 }
1096 out.push_str("\nDefinitions found:\n");
1097 let def_patterns = [
1098 "fn ",
1099 "pub fn ",
1100 "async fn ",
1101 "def ",
1102 "func ",
1103 "function ",
1104 "class ",
1105 "struct ",
1106 "enum ",
1107 "trait ",
1108 "impl ",
1109 "interface ",
1110 "type ",
1111 "const ",
1112 "#define ",
1113 "namespace ",
1114 ];
1115 for (i, line) in content.lines().enumerate() {
1116 let trimmed = line.trim();
1117 if def_patterns.iter().any(|p| trimmed.starts_with(p)) {
1118 let short = if trimmed.len() > 100 {
1119 let end = truncate_to_char_boundary(trimmed, 97);
1120 format!("{}...", &trimmed[..end])
1121 } else {
1122 trimmed.to_string()
1123 };
1124 out.push_str(&format!(" L{}: {}\n", i + 1, short));
1125 }
1126 }

Callers 1

exec_read_fileMethod · 0.85

Calls 4

linesMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected