Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Introduce line-breaks in multiline arguments #1244

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

IndrajeetPatil
Copy link
Collaborator

cf. tidyverse/style#209

Creating an early PR because I'm having a hard time figuring out the scope of this change. The motivating issue and the style guide don't go into too much depth as to when one should introduce line breaks in the context of multi-line arguments. But this should act as a good starting point.


This is an adapted version of a similar feature in grkstyle.

Examples

styler::style_text("
list(
  c(
    a
  ), c(
    b
  )
)
")
#> list(
#>   c(
#>     a
#>   ),
#>   c(
#>     b
#>   )
#> )

styler::style_text("c(1, 2, 3)")
#> c(1, 2, 3)

styler::style_text("c(1, 
                   2, 3)")
#> c(
#>   1,
#>   2,
#>   3
#> )


'tribble(
  ~x,       ~d,
  "b",      4:6
)' -> code
styler::style_text(code)
#> tribble(
#>   ~x,       ~d,
#>   "b",      4:6
#> )

Created on 2024-12-06 with reprex v2.1.1

This comment was marked as outdated.

This comment was marked as outdated.

@IndrajeetPatil
Copy link
Collaborator Author

Wow, that's quite the slowdown. Need to figure out what's causing it once the scope is clear.

This comment was marked as outdated.

Copy link
Contributor

github-actions bot commented Dec 9, 2024

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 27b5eca is merged into main:

  • ✔️cache_applying: 164ms -> 162ms [-4.68%, +1.83%]
  • ❗🐌cache_recording: 542ms -> 1.27s [+128.12%, +139.62%]
  • ❗🐌without_cache: 1000ms -> 2.42s [+137.76%, +146.26%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@IndrajeetPatil
Copy link
Collaborator Author

@lorenzwalthert Any thoughts?

I am blocked here without any further feedback from the team.

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Dec 12, 2024

Maybe we should talk about the abstract rule first. What is it exactly that we try to achieve?
As for the code, I just wanted to say that you can easily figure out if there are line-breaks in a nest by looking at the respective column. To figure out if there are line breaks hidden in one of the children, consier the is_multi_line column. That will save you a lot of computations I think.

Also important: in the example you gave, all line breaks should simply be removed if we had #247.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants