diff --git a/crates/pi-ast/src/summary.rs b/crates/pi-ast/src/summary.rs index 7885e7850..a246d2b29 100644 --- a/crates/pi-ast/src/summary.rs +++ b/crates/pi-ast/src/summary.rs @@ -15,15 +15,15 @@ const DEFAULT_MIN_COMMENT_LINES: u32 = 6; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SummaryOptions { /// Source code to summarize. - pub code: String, + pub code: String, /// Language alias (e.g. "rust", "typescript") used before path inference. - pub lang: Option, + pub lang: Option, /// File path used to infer language by extension when `lang` is omitted. - pub path: Option, + pub path: Option, /// Minimum total node lines before eliding a body/literal node. - pub min_body_lines: Option, + pub min_body_lines: Option, /// Minimum total comment lines before eliding a multiline block comment. - pub min_comment_lines: Option, + pub min_comment_lines: Option, /// Target visible-line count for BFS unfold. Starting from every elidable /// span folded, this progressively reveals outer-then-inner spans until /// the visible line count meets the target. `None` or `0` disables BFS @@ -293,7 +293,14 @@ fn collect_elidable_tree( run_last = Some(child); run_count += 1; } else { - flush_groupable_run(run_first, run_last, run_count, min_body_lines, forest, current_parent); + flush_groupable_run( + run_first, + run_last, + run_count, + min_body_lines, + forest, + current_parent, + ); run_first = None; run_last = None; run_count = 0; @@ -303,7 +310,14 @@ fn collect_elidable_tree( for index in 0..child_count { if let Some(child) = node.child(index) { - collect_elidable_tree(child, current_parent, language, min_body_lines, min_comment_lines, forest); + collect_elidable_tree( + child, + current_parent, + language, + min_body_lines, + min_comment_lines, + forest, + ); } } } @@ -866,11 +880,11 @@ mod tests { fn summarize(code: &str, path: &str) -> SummaryResult { summarize_code(SummaryOptions { - code: code.to_string(), - lang: None, - path: Some(path.to_string()), - min_body_lines: None, - min_comment_lines: None, + code: code.to_string(), + lang: None, + path: Some(path.to_string()), + min_body_lines: None, + min_comment_lines: None, unfold_until_lines: None, unfold_limit_lines: None, }) @@ -962,11 +976,11 @@ mod tests { assert!(!default_result.elided); let override_result = summarize_code(SummaryOptions { - code: code.to_string(), - lang: Some("typescript".to_string()), - path: None, - min_body_lines: Some(3), - min_comment_lines: None, + code: code.to_string(), + lang: Some("typescript".to_string()), + path: None, + min_body_lines: Some(3), + min_comment_lines: None, unfold_until_lines: None, unfold_limit_lines: None, }) @@ -1220,7 +1234,8 @@ mod tests { let code = (0..10) .map(|i| { format!( - "export function fn{i}(): number {{\n\tconst a = {i};\n\tconst b = {i};\n\tconst c = {i};\n\treturn a + b + c;\n}}" + "export function fn{i}(): number {{\n\tconst a = {i};\n\tconst b = {i};\n\tconst c \ + = {i};\n\treturn a + b + c;\n}}" ) }) .collect::>() @@ -1228,7 +1243,11 @@ mod tests { let result = summarize_with_unfold(&code, "fixture.ts", 10, 100); assert!(result.elided); - let elided_count = result.segments.iter().filter(|s| s.kind == "elided").count(); + let elided_count = result + .segments + .iter() + .filter(|s| s.kind == "elided") + .count(); assert_eq!(elided_count, 10); } @@ -1247,6 +1266,13 @@ mod tests { // BFS reverts and leaves the body folded. let result = summarize_with_unfold(&code, "big.ts", 10, 30); // Exactly one elided segment for the function body. - assert_eq!(result.segments.iter().filter(|s| s.kind == "elided").count(), 1); + assert_eq!( + result + .segments + .iter() + .filter(|s| s.kind == "elided") + .count(), + 1 + ); } } diff --git a/crates/pi-natives/src/summary.rs b/crates/pi-natives/src/summary.rs index 50464cd88..9d427fe19 100644 --- a/crates/pi-natives/src/summary.rs +++ b/crates/pi-natives/src/summary.rs @@ -6,15 +6,15 @@ use napi_derive::napi; #[napi(object)] pub struct SummaryOptions { /// Source code to summarize. - pub code: String, + pub code: String, /// Language alias (e.g. "rust", "typescript") used before path inference. - pub lang: Option, + pub lang: Option, /// File path used to infer language by extension when `lang` is omitted. - pub path: Option, + pub path: Option, /// Minimum total node lines before eliding a body/literal node. - pub min_body_lines: Option, + pub min_body_lines: Option, /// Minimum total comment lines before eliding a multiline block comment. - pub min_comment_lines: Option, + pub min_comment_lines: Option, /// Target visible-line count for BFS unfold. `None` or `0` keeps only /// the outermost elisions (no progressive unfolding). pub unfold_until_lines: Option, @@ -75,11 +75,11 @@ impl From for SummaryResult { #[napi] pub fn summarize_code(options: SummaryOptions) -> Result { pi_ast::summary::summarize_code(pi_ast::summary::SummaryOptions { - code: options.code, - lang: options.lang, - path: options.path, - min_body_lines: options.min_body_lines, - min_comment_lines: options.min_comment_lines, + code: options.code, + lang: options.lang, + path: options.path, + min_body_lines: options.min_body_lines, + min_comment_lines: options.min_comment_lines, unfold_until_lines: options.unfold_until_lines, unfold_limit_lines: options.unfold_limit_lines, })