mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +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
|
@ -482,11 +482,13 @@ mod tests {
|
|||
use ruff_formatter::SourceCode;
|
||||
use ruff_python_ast::{Mod, PySourceType};
|
||||
use ruff_python_parser::{parse, AsMode, Parsed};
|
||||
use ruff_python_trivia::CommentRanges;
|
||||
|
||||
use crate::comments::Comments;
|
||||
|
||||
struct CommentsTestCase<'a> {
|
||||
parsed: Parsed<Mod>,
|
||||
comment_ranges: CommentRanges,
|
||||
source_code: SourceCode<'a>,
|
||||
}
|
||||
|
||||
|
@ -496,19 +498,17 @@ mod tests {
|
|||
let source_type = PySourceType::Python;
|
||||
let parsed =
|
||||
parse(source, source_type.as_mode()).expect("Expect source to be valid Python");
|
||||
let comment_ranges = CommentRanges::from(parsed.tokens());
|
||||
|
||||
CommentsTestCase {
|
||||
parsed,
|
||||
comment_ranges,
|
||||
source_code,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_comments(&self) -> Comments {
|
||||
Comments::from_ast(
|
||||
self.parsed.syntax(),
|
||||
self.source_code,
|
||||
self.parsed.comment_ranges(),
|
||||
)
|
||||
Comments::from_ast(self.parsed.syntax(), self.source_code, &self.comment_ranges)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue