Fix continuation detection following multi-line strings (#9332)

## Summary

The logic that detects continuations assumed that tokens themselves
cannot span multiple lines. However, strings _can_ -- even single-quoted
strings.

Closes https://github.com/astral-sh/ruff/issues/9323.
This commit is contained in:
Charlie Marsh 2023-12-31 11:43:35 -04:00 committed by GitHub
parent 003851c41d
commit b3789cd9e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 2 deletions

View file

@ -62,13 +62,22 @@ impl Indexer {
comment_ranges_builder.visit_token(tok, *range);
fstring_ranges_builder.visit_token(tok, *range);
if matches!(tok, Tok::Newline | Tok::NonLogicalNewline) {
line_start = range.end();
match tok {
Tok::Newline | Tok::NonLogicalNewline => {
line_start = range.end();
}
Tok::String { .. } => {
// If the previous token was a string, find the start of the line that contains
// the closing delimiter, since the token itself can span multiple lines.
line_start = locator.line_start(range.end());
}
_ => {}
}
prev_token = Some(tok);
prev_end = range.end();
}
Self {
comment_ranges: comment_ranges_builder.finish(),
continuation_lines,