mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
Move has_comments
to CommentRanges
(#11495)
## Summary This PR moves the `has_comments` function from `Indexer` to `CommentRanges`. The main motivation is that the `CommentRanges` will now be built by the parser which is shared between the linter and the formatter. Thus, the `CommentRanges` will be removed from the `Indexer`. ## Test Plan `cargo test`
This commit is contained in:
parent
5bb9720a10
commit
f0046ab28e
10 changed files with 65 additions and 29 deletions
|
@ -112,25 +112,6 @@ impl Indexer {
|
|||
self.continuation_lines.binary_search(&line_start).is_ok()
|
||||
}
|
||||
|
||||
/// Returns `true` if a statement or expression includes at least one comment.
|
||||
pub fn has_comments<T>(&self, node: &T, locator: &Locator) -> bool
|
||||
where
|
||||
T: Ranged,
|
||||
{
|
||||
let start = if has_leading_content(node.start(), locator) {
|
||||
node.start()
|
||||
} else {
|
||||
locator.line_start(node.start())
|
||||
};
|
||||
let end = if has_trailing_content(node.end(), locator) {
|
||||
node.end()
|
||||
} else {
|
||||
locator.line_end(node.end())
|
||||
};
|
||||
|
||||
self.comment_ranges().intersects(TextRange::new(start, end))
|
||||
}
|
||||
|
||||
/// Given an offset at the end of a line (including newlines), return the offset of the
|
||||
/// continuation at the end of that line.
|
||||
fn find_continuation(&self, offset: TextSize, locator: &Locator) -> Option<TextSize> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue