Skip to content

Commit f421fb7

Browse files
haasonsaasclaude
andcommitted
fix: restrict # comment detection to languages that use it
Limit # as a comment indicator to Python/Ruby/Shell only, not C/C++/Rust/Java where # starts preprocessor directives or attributes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4c67db5 commit f421fb7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/function_chunker.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,16 @@ fn find_function_end(lines: &[&str], start: usize, language: &str) -> usize {
265265
prev_ch = ch;
266266
continue;
267267
}
268-
// Skip line comments: // in most languages, # in Python/Ruby/Shell
268+
// Skip line comments: // in C-family languages,
269+
// # in Python/Ruby/Shell (but not in C/C++/Rust/Java
270+
// where # is a preprocessor directive or attribute)
269271
if !in_double_quote && !in_single_quote {
270272
if ch == '/' && prev_ch == '/' {
271273
break; // rest of line is a comment
272274
}
273-
if ch == '#' && !in_double_quote && !in_single_quote {
275+
if ch == '#'
276+
&& matches!(language, "py" | "rb" | "sh" | "bash" | "zsh" | "r")
277+
{
274278
break; // rest of line is a comment
275279
}
276280
}

0 commit comments

Comments
 (0)