posit-dev / posit-dev/air

Table directives in argument lists do not work

Open
#433 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
446
Forks
32
Avg merge
16h 48m
Merged PRs (30d)
1

Description

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: R_CALL@0..71
              0: R_IDENTIFIER@0..14
                0: IDENT@0..14 "matrix" [Comments("# outer"), Newline("\n")] []
              1: R_CALL_ARGUMENTS@14..71
                0: L_PAREN@14..15 "(" [] []
                1: R_ARGUMENT_LIST@15..69
                  0: R_ARGUMENT@15..69
                    0: (empty)
                    1: R_CALL@15..69
                      0: R_IDENTIFIER@15..34
                        0: IDENT@15..34 "c" [Newline("\n"), Whitespace("  "), Comments("# fmt: table"), Newline("\n"), Whitespace("  ")] []
                      1: R_CALL_ARGUMENTS@34..69
                        0: L_PAREN@34..35 "(" [] []
                        1: R_ARGUMENT_LIST@35..65
                          0: R_ARGUMENT@35..41
                            0: (empty)
                            1: R_DOUBLE_VALUE@35..41
                              0: R_DOUBLE_LITERAL@35..41 "1" [Newline("\n"), Whitespace("    ")] []
                          1: COMMA@41..42 "," [] []
                          2: R_ARGUMENT@42..48
                            0: (empty)
                            1: R_DOUBLE_VALUE@42..48
                              0: R_DOUBLE_LITERAL@42..48 "2" [Newline("\n"), Whitespace("    ")] []
                          3: COMMA@48..49 "," [] []
                          4: R_ARGUMENT@49..56
                            0: (empty)
                            1: R_DOUBLE_VALUE@49..56
                              0: R_DOUBLE_LITERAL@49..56 "10" [Newline("\n"), Whitespace("    ")] []
                          5: COMMA@56..57 "," [] []
                          6: R_ARGUMENT@57..65
                            0: (empty)
                            1: R_DOUBLE_VALUE@57..65
                              0: R_DOUBLE_LITERAL@57..65 "200" [Newline("\n"), Whitespace("    ")] []
                        2: R_PAREN@65..69 ")" [Newline("\n"), Whitespace("  ")] []
                2: R_PAREN@69..71 ")" [Newline("\n")] []
            ,
            comment: SourceComment {
                lines_before: 0,
                lines_after: 1,
                piece: SyntaxTriviaPieceComments(
                    Comments("# outer"),
                ),
                kind: Line,
                formatted: Cell {
                    value: true,
                },
            },
        },
        Leading {
            node: 0: R_ARGUMENT@15..69
              0: (empty)
              1: R_CALL@15..69
                0: R_IDENTIFIER@15..34
                  0: IDENT@15..34 "c" [Newline("\n"), Whitespace("  "), Comments("# fmt: table"), Newline("\n"), Whitespace("  ")] []
                1: R_CALL_ARGUMENTS@34..69
                  0: L_PAREN@34..35 "(" [] []
                  1: R_ARGUMENT_LIST@35..65
                    0: R_ARGUMENT@35..41
                      0: (empty)
                      1: R_DOUBLE_VALUE@35..41
                        0: R_DOUBLE_LITERAL@35..41 "1" [Newline("\n"), Whitespace("    ")] []
                    1: COMMA@41..42 "," [] []
                    2: R_ARGUMENT@42..48
                      0: (empty)
                      1: R_DOUBLE_VALUE@42..48
                        0: R_DOUBLE_LITERAL@42..48 "2" [Newline("\n"), Whitespace("    ")] []
                    3: COMMA@48..49 "," [] []
                    4: R_ARGUMENT@49..56
                      0: (empty)
                      1: R_DOUBLE_VALUE@49..56
                        0: R_DOUBLE_LITERAL@49..56 "10" [Newline("\n"), Whitespace("    ")] []
                    5: COMMA@56..57 "," [] []
                    6: R_ARGUMENT@57..65
                      0: (empty)
                      1: R_DOUBLE_VALUE@57..65
                        0: R_DOUBLE_LITERAL@57..65 "200" [Newline("\n"), Whitespace("    ")] []
                  2: R_PAREN@65..69 ")" [Newline("\n"), Whitespace("  ")] []
            ,
            comment: SourceComment {
                lines_before: 1,
                lines_after: 1,
                piece: SyntaxTriviaPieceComments(
                    Comments("# fmt: table"),
                ),
                kind: Line,
                formatted: Cell {
                    value: true,
                },
            },
        },
    ],
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/air_r_formatter/src/comments_ext.rs, especially can_have_directives(), and inspect how comments attached to R_ARGUMENT nodes are handled. Reproduce the nested matrix() and c() example with the # fmt: table directive; done means table formatting works for directives inside argument lists and the comment attachment is handled correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.