mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 23:57:35 +00:00
Use CommentRanges in backwards lexing (#7360)
## Summary The tokenizer was split into a forward and a backwards tokenizer. The backwards tokenizer uses the same names as the forwards ones (e.g. `next_token`). The backwards tokenizer gets the comment ranges that we already built to skip comments. --------- Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
1f6e1485f9
commit
2cbe1733c8
41 changed files with 744 additions and 628 deletions
|
@ -561,6 +561,7 @@ impl Format<PyFormatContext<'_>> for SuiteChildStatement<'_> {
|
|||
mod tests {
|
||||
use ruff_formatter::format;
|
||||
use ruff_python_parser::parse_suite;
|
||||
use ruff_python_trivia::CommentRanges;
|
||||
|
||||
use crate::comments::Comments;
|
||||
use crate::prelude::*;
|
||||
|
@ -591,7 +592,12 @@ def trailing_func():
|
|||
|
||||
let statements = parse_suite(source, "test.py").unwrap();
|
||||
|
||||
let context = PyFormatContext::new(PyFormatOptions::default(), source, Comments::default());
|
||||
let comment_ranges = CommentRanges::default();
|
||||
let context = PyFormatContext::new(
|
||||
PyFormatOptions::default(),
|
||||
source,
|
||||
Comments::from_ranges(&comment_ranges),
|
||||
);
|
||||
|
||||
let test_formatter =
|
||||
format_with(|f: &mut PyFormatter| statements.format().with_options(level).fmt(f));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue