Skip to content

Commit b312a24

Browse files
haasonsaasclaude
andcommitted
fix: address PR review feedback — Rust lifetimes and shebang detection
- Skip single-quote tracking for Rust in find_function_end (lifetimes like 'a/'static are not string delimiters, were breaking brace count) - Add #!/ to HASH_NON_COMMENT_PREFIXES so shebang lines are not misclassified as comments (changing interpreter is a real code change) - Added 2 regression tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 26ae42a commit b312a24

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/core/function_chunker.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn find_function_end(lines: &[&str], start: usize, language: &str) -> usize {
265265
escaped = true;
266266
} else if ch == '"' && !in_single_quote {
267267
in_double_quote = !in_double_quote;
268-
} else if ch == '\'' && !in_double_quote {
268+
} else if ch == '\'' && !in_double_quote && language != "rs" {
269269
in_single_quote = !in_single_quote;
270270
} else if !in_double_quote && !in_single_quote {
271271
if ch == '{' {
@@ -934,6 +934,24 @@ fn next_func() {
934934
);
935935
}
936936

937+
#[test]
938+
fn test_find_function_end_rust_lifetime_not_string() {
939+
// BUG: Rust lifetime annotations ('a, 'static) toggle in_single_quote,
940+
// causing the opening brace on the same line to be ignored.
941+
let lines: Vec<&str> = vec![
942+
"pub fn new(name: &'static str) -> Self {", // line 0: has lifetime '
943+
" Self { name }", // line 1
944+
"}", // line 2
945+
"",
946+
"fn other() {", // line 4
947+
];
948+
let end = find_function_end(&lines, 0, "rs");
949+
assert_eq!(
950+
end, 2,
951+
"Rust lifetime annotation should not break brace tracking"
952+
);
953+
}
954+
937955
#[test]
938956
fn test_find_function_end_escaped_backslash_in_string() {
939957
// A string containing "\\" (escaped backslash) on the same line as braces.

src/review/triage.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const COMMENT_PREFIXES: &[&str] = &["//", "# ", "/*", "*/", "* ", "--", "<!--",
4545

4646
/// Patterns that start with `#` but are NOT comments (Rust attributes, C preprocessor, etc.).
4747
const HASH_NON_COMMENT_PREFIXES: &[&str] = &[
48-
"#[", "#![", "#include", "#define", "#ifdef", "#ifndef", "#endif", "#pragma", "#undef", "#elif",
49-
"#else", "#if ", "#error", "#warning", "#line",
48+
"#[", "#![", "#!/", "#include", "#define", "#ifdef", "#ifndef", "#endif", "#pragma", "#undef",
49+
"#elif", "#else", "#if ", "#error", "#warning", "#line",
5050
];
5151

5252
/// Classify a diff using fast heuristics (no LLM call).
@@ -983,6 +983,20 @@ mod tests {
983983
assert_eq!(triage_diff(&diff), TriageResult::SkipCommentOnly);
984984
}
985985

986+
#[test]
987+
fn test_shebang_line_is_not_comment() {
988+
// Shebang lines (#!/usr/bin/env python3) change runtime behavior
989+
// and should NOT be classified as comments
990+
let diff = make_diff(
991+
"script.py",
992+
vec![
993+
make_line(1, ChangeType::Removed, "#!/usr/bin/env python2"),
994+
make_line(1, ChangeType::Added, "#!/usr/bin/env python3"),
995+
],
996+
);
997+
assert_eq!(triage_diff(&diff), TriageResult::NeedsReview);
998+
}
999+
9861000
#[test]
9871001
fn test_all_blank_lines_is_comment_only() {
9881002
// Blank lines count as "comment" in is_comment_line

0 commit comments

Comments
 (0)