mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:16 +00:00
Build CommentRanges
outside the parser (#11792)
## Summary This PR updates the parser to remove building the `CommentRanges` and instead it'll be built by the linter and the formatter when it's required. For the linter, it'll be built and owned by the `Indexer` while for the formatter it'll be built from the `Tokens` struct and passed as an argument. ## Test Plan `cargo insta test`
This commit is contained in:
parent
7509a48eab
commit
549cc1e437
28 changed files with 151 additions and 102 deletions
|
@ -831,6 +831,7 @@ impl Format<PyFormatContext<'_>> for SuiteChildStatement<'_> {
|
|||
mod tests {
|
||||
use ruff_formatter::format;
|
||||
use ruff_python_parser::parse_module;
|
||||
use ruff_python_trivia::CommentRanges;
|
||||
|
||||
use crate::comments::Comments;
|
||||
use crate::prelude::*;
|
||||
|
@ -860,11 +861,12 @@ def trailing_func():
|
|||
";
|
||||
|
||||
let parsed = parse_module(source).unwrap();
|
||||
let comment_ranges = CommentRanges::from(parsed.tokens());
|
||||
|
||||
let context = PyFormatContext::new(
|
||||
PyFormatOptions::default(),
|
||||
source,
|
||||
Comments::from_ranges(parsed.comment_ranges()),
|
||||
Comments::from_ranges(&comment_ranges),
|
||||
parsed.tokens(),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue