Skip to content

Commit

Permalink
Show header for formatter comment decoration info
Browse files Browse the repository at this point in the history
**Summary** Show a header in the formatter comment decoration debug output that shows which node is preceding/following/enclosing (#6813 (comment)). I also kept this intentionally condensed to make it easy to use this is a small sidebar without vertical scrolling.

```
# Comment decoration: Range Preceding Following Enclosing Comment
1292..1298 Some((ExprName, 1274..1280)) Some((ExprName, 1307..1310)) (StmtAnnAssign, 1274..1316) "# type"
2507..2555 None Some((StmtIf, 2634..2891)) (StmtClassDef, 2478..3279) "# didn't match the name in the C implementation,"
2560..2629 None Some((StmtIf, 2634..2891)) (StmtClassDef, 2478..3279) "# meaning it is only *safe* to pass it as a keyword argument on 3.12+"
3281..3298 Some((StmtClassDef, 2478..3279)) Some((StmtFunctionDef, 3300..3317)) (ModModule, 0..4162) "# Top level rules"
3481..3496 Some((StmtClassDef, 3452..3479)) Some((StmtClassDef, 3498..3876)) (ModModule, 0..4162) "# Nesting rules"
{
    Node {
        kind: ExprName,
        range: 1307..1310,
        source: `int`,
    }: {
...
```

**Test Plan** It's debug output.
  • Loading branch information
konstin committed Sep 8, 2023
1 parent a352f2f commit 4244ad5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/ruff_python_formatter/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub fn format_and_debug_print(input: &str, cli: &Cli, source_type: &Path) -> Res
// Print preceding, following and enclosing nodes
let source_code = SourceCode::new(input);
let decorated_comments = collect_comments(&python_ast, source_code, &comment_ranges);
if !decorated_comments.is_empty() {
println!("# Comment decoration: Range Preceding Following Enclosing Comment");
}
for comment in decorated_comments {
println!(
"{:?} {:?} {:?} {:?} {:?}",
Expand Down

0 comments on commit 4244ad5

Please sign in to comment.