MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / collect_block_text

Function collect_block_text

crates/opencode-config/src/loader.rs:1082–1115  ·  view source on GitHub ↗

Collect indented block text lines (for block scalars or multi-line values). Stops when a line at or below `parent_indent` is encountered.

(lines: &[&str], start: usize, parent_indent: usize)

Source from the content-addressed store, hash-verified

1080/// Collect indented block text lines (for block scalars or multi-line values).
1081/// Stops when a line at or below `parent_indent` is encountered.
1082fn collect_block_text(lines: &[&str], start: usize, parent_indent: usize) -> (String, usize) {
1083 let mut text_lines = Vec::new();
1084 let mut i = start;
1085 let mut block_indent: Option<usize> = None;
1086
1087 while i < lines.len() {
1088 let line = lines[i];
1089 // Empty lines are part of the block
1090 if line.trim().is_empty() {
1091 text_lines.push("");
1092 i += 1;
1093 continue;
1094 }
1095 let current_indent = indent_level(line);
1096 if current_indent <= parent_indent {
1097 break;
1098 }
1099 // Determine the block's base indent from the first non-empty line
1100 let bi = *block_indent.get_or_insert(current_indent);
1101 if current_indent >= bi {
1102 text_lines.push(&line[bi..]);
1103 } else {
1104 text_lines.push(line.trim());
1105 }
1106 i += 1;
1107 }
1108
1109 // Trim trailing empty lines
1110 while text_lines.last() == Some(&"") {
1111 text_lines.pop();
1112 }
1113
1114 (text_lines.join("\n"), i)
1115}
1116
1117/// Derive a name from a file path relative to the base directory.
1118fn derive_name_from_path(path: &Path, base_dir: &Path, strip_prefixes: &[&str]) -> String {

Callers 1

parse_yaml_mapping_linesFunction · 0.85

Calls 3

newFunction · 0.85
indent_levelFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected