Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions src/core/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down