mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
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:
1 parent
f482e0c2cf
commit
e50103281d
1 file changed
+11
-8
@@ -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,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user