Fix single-input multiple-statement diagnostic ranges (#9289)

Preserve comment spans and count a logical newline once when converting
single-mode multiple-statement diagnostics to character locations.

Assisted-by: OpenAI Codex:model-version-unavailable
This commit is contained in:
youknowdot authored and GitHub committed 2026-10-22 10:17:41 +09:00
1 parent f482e0c2cf
commit e50103281d
1 file changed
+11 -8
+11 -8
View File
@@ -1339,15 +1339,18 @@ pub fn single_mode_multiple_statements_error(
let position = match newline_index.checked_sub(1).map(|index| &tokens[index]) {
Some(comment) if comment.kind() == TokenKind::Comment => comment.start(),
_ => newline.start(),
}
.to_usize();
Some(CompileError::from_source_error(
};
// Include the comment and one logical newline character. Using the token's
// full end would count both bytes of CRLF; position + 1 truncates comments.
Some(CompileError::from_ruff_parse_error(
parser::ParseError {
error: parser::ParseErrorType::OtherError(
"multiple statements found while compiling a single statement".to_owned(),
),
location: ruff_text_size::TextRange::new(position, newline.start() + TextSize::new(1)),
},
source_file,
CpythonDiagnostic::new(
"multiple statements found while compiling a single statement".to_owned(),
position,
position,
),
Mode::Single,
))
}