Skip to content

Table directives in argument lists do not work #433

@lionel-

Description

@lionel-

E.g. for cases like:

# In argument
x <- matrix(
  # fmt: table
  c(
    1, 2,
    10, 200
  ),
  ncol = 2
)

I see two issues.

  • In can_have_directives(), we're checking whether the parent is an argument list, rather than an argument.
  • Comments get attached to argument nodes, not call nodes. Which is probably fine? But we need to acknowledge that.
Details
[crates/air_r_formatter/src/comments_ext.rs:46:9] self = Comments {
    data: [
        Leading {
            node: 0: [email protected]
              0: [email protected]
                0: [email protected] "matrix" [Comments("# outer"), Newline("\n")] []
              1: [email protected]
                0: [email protected] "(" [] []
                1: [email protected]
                  0: [email protected]
                    0: (empty)
                    1: [email protected]
                      0: [email protected]
                        0: [email protected] "c" [Newline("\n"), Whitespace("  "), Comments("# fmt: table"), Newline("\n"), Whitespace("  ")] []
                      1: [email protected]
                        0: [email protected] "(" [] []
                        1: [email protected]
                          0: [email protected]
                            0: (empty)
                            1: [email protected]
                              0: [email protected] "1" [Newline("\n"), Whitespace("    ")] []
                          1: [email protected] "," [] []
                          2: [email protected]
                            0: (empty)
                            1: [email protected]
                              0: [email protected] "2" [Newline("\n"), Whitespace("    ")] []
                          3: [email protected] "," [] []
                          4: [email protected]
                            0: (empty)
                            1: [email protected]
                              0: [email protected] "10" [Newline("\n"), Whitespace("    ")] []
                          5: [email protected] "," [] []
                          6: [email protected]
                            0: (empty)
                            1: [email protected]
                              0: [email protected] "200" [Newline("\n"), Whitespace("    ")] []
                        2: [email protected] ")" [Newline("\n"), Whitespace("  ")] []
                2: [email protected] ")" [Newline("\n")] []
            ,
            comment: SourceComment {
                lines_before: 0,
                lines_after: 1,
                piece: SyntaxTriviaPieceComments(
                    Comments("# outer"),
                ),
                kind: Line,
                formatted: Cell {
                    value: true,
                },
            },
        },
        Leading {
            node: 0: [email protected]
              0: (empty)
              1: [email protected]
                0: [email protected]
                  0: [email protected] "c" [Newline("\n"), Whitespace("  "), Comments("# fmt: table"), Newline("\n"), Whitespace("  ")] []
                1: [email protected]
                  0: [email protected] "(" [] []
                  1: [email protected]
                    0: [email protected]
                      0: (empty)
                      1: [email protected]
                        0: [email protected] "1" [Newline("\n"), Whitespace("    ")] []
                    1: [email protected] "," [] []
                    2: [email protected]
                      0: (empty)
                      1: [email protected]
                        0: [email protected] "2" [Newline("\n"), Whitespace("    ")] []
                    3: [email protected] "," [] []
                    4: [email protected]
                      0: (empty)
                      1: [email protected]
                        0: [email protected] "10" [Newline("\n"), Whitespace("    ")] []
                    5: [email protected] "," [] []
                    6: [email protected]
                      0: (empty)
                      1: [email protected]
                        0: [email protected] "200" [Newline("\n"), Whitespace("    ")] []
                  2: [email protected] ")" [Newline("\n"), Whitespace("  ")] []
            ,
            comment: SourceComment {
                lines_before: 1,
                lines_after: 1,
                piece: SyntaxTriviaPieceComments(
                    Comments("# fmt: table"),
                ),
                kind: Line,
                formatted: Cell {
                    value: true,
                },
            },
        },
    ],
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions