From 1524fcefd77d71c31bed00abbbaf8e2cfb5e9940 Mon Sep 17 00:00:00 2001 From: andiahmads Date: Tue, 23 Jun 2026 15:25:02 +0700 Subject: [PATCH] fix(filter): preserve inline comment markers in code --- src/core/filter.rs | 55 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/core/filter.rs b/src/core/filter.rs index 90f89ade65..3eb8289f5e 100644 --- a/src/core/filter.rs +++ b/src/core/filter.rs @@ -170,20 +170,23 @@ impl FilterStrategy for MinimalFilter { for line in content.lines() { let trimmed = line.trim(); - // Handle block comments + // Handle full-line block comments. if let (Some(start), Some(end)) = (patterns.block_start, patterns.block_end) { - if !in_docstring - && trimmed.contains(start) - && !trimmed.starts_with(patterns.doc_block_start.unwrap_or("###")) - { - in_block_comment = true; - } if in_block_comment { if trimmed.contains(end) { in_block_comment = false; } continue; } + if !in_docstring + && trimmed.starts_with(start) + && !trimmed.starts_with(patterns.doc_block_start.unwrap_or("###")) + { + if !trimmed.contains(end) { + in_block_comment = true; + } + continue; + } } // Handle Python docstrings (keep them in minimal mode) @@ -470,6 +473,44 @@ fn main() { assert!(result.contains("fn main()")); } + #[test] + fn test_minimal_filter_preserves_comment_markers_inside_code() { + let code = r#" +const API: &str = "http://example.com/v1"; // endpoint +let re = regex::Regex::new(r"https?://\w+").unwrap(); +let glob = "packages/*"; +let inline = call(/* keep this expression line */); +fn foo() {} +"#; + let filter = MinimalFilter; + let result = filter.filter(code, &Language::Rust); + + assert!(result.contains(r#"const API: &str = "http://example.com/v1";"#)); + assert!(result.contains(r#"let re = regex::Regex::new(r"https?://\w+").unwrap();"#)); + assert!(result.contains(r#"let glob = "packages/*";"#)); + assert!(result.contains("let inline = call(/* keep this expression line */);")); + assert!(result.contains("fn foo() {}")); + } + + #[test] + fn test_minimal_filter_removes_full_line_block_comments_only() { + let code = r#" +fn before() {} +/* single-line block comment */ +/* + * multi-line block comment + */ +fn after() {} +"#; + let filter = MinimalFilter; + let result = filter.filter(code, &Language::Rust); + + assert!(result.contains("fn before() {}")); + assert!(result.contains("fn after() {}")); + assert!(!result.contains("single-line block comment")); + assert!(!result.contains("multi-line block comment")); + } + // --- truncation accuracy --- #[test]