mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
Correctly associate own-line comments in bodies (#4671)
This commit is contained in:
parent
46c3b3af94
commit
be31d71849
16 changed files with 1747 additions and 144 deletions
|
@ -1,5 +1,6 @@
|
|||
use crate::comments::node_key::NodeRefEqualityKey;
|
||||
use crate::comments::{CommentsMap, SourceComment};
|
||||
use itertools::Itertools;
|
||||
use ruff_formatter::SourceCode;
|
||||
use ruff_python_ast::prelude::*;
|
||||
use std::fmt::{Debug, Formatter, Write};
|
||||
|
@ -53,7 +54,7 @@ impl Debug for DebugComments<'_> {
|
|||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let mut map = f.debug_map();
|
||||
|
||||
for node in self.comments.keys() {
|
||||
for node in self.comments.keys().sorted_by_key(|key| key.node().start()) {
|
||||
map.entry(
|
||||
&NodeKindWithSource {
|
||||
key: *node,
|
||||
|
@ -176,19 +177,13 @@ impl Debug for DebugNodeCommentSlice<'_> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::comments::map::MultiMap;
|
||||
use crate::comments::node_key::NodeRefEqualityKey;
|
||||
use crate::comments::{
|
||||
CommentTextPosition, Comments, CommentsData, CommentsMap, SourceComment,
|
||||
};
|
||||
use insta::_macro_support::assert_snapshot;
|
||||
use insta::{assert_debug_snapshot, assert_snapshot};
|
||||
use crate::comments::{CommentTextPosition, Comments, CommentsMap, SourceComment};
|
||||
use insta::assert_debug_snapshot;
|
||||
use ruff_formatter::SourceCode;
|
||||
use ruff_python_ast::node::AnyNode;
|
||||
use ruff_python_ast::source_code;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use rustpython_parser::ast::{StmtBreak, StmtContinue};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[test]
|
||||
fn debug() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue