Add token based parenthesized_ranges implementation (#21738)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Denys Zhak
2025-12-03 09:15:17 +01:00
committed by GitHub
parent e6ddeed386
commit f4e4229683
6 changed files with 339 additions and 80 deletions

View File

@@ -37,13 +37,11 @@ use itertools::Itertools;
use ruff_db::{
diagnostic::{Annotation, Diagnostic, Span, SubDiagnostic, SubDiagnosticSeverity},
parsed::parsed_module,
source::source_text,
};
use ruff_diagnostics::{Edit, Fix};
use ruff_python_ast::name::Name;
use ruff_python_ast::parenthesize::parentheses_iterator;
use ruff_python_ast::token::parentheses_iterator;
use ruff_python_ast::{self as ast, AnyNodeRef, StringFlags};
use ruff_python_trivia::CommentRanges;
use ruff_text_size::{Ranged, TextRange};
use rustc_hash::FxHashSet;
use std::fmt::{self, Formatter};
@@ -2423,9 +2421,7 @@ pub(super) fn report_invalid_assignment<'db>(
// ) # ty: ignore <- or here
// ```
let comment_ranges = CommentRanges::from(context.module().tokens());
let source = source_text(context.db(), context.file());
parentheses_iterator(value_node.into(), None, &comment_ranges, &source)
parentheses_iterator(value_node.into(), None, context.module().tokens())
.last()
.unwrap_or(value_node.range())
} else {