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

Add onEnterRules for regular old comments in R #6049

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

juliasilge
Copy link
Contributor

Addresses #5974

The order in this JSON file is important; if you put the regular comment rule before the ones for plumber and roxygen, it takes precedence and we lose the special behavior for plumber and roxygen. It has to go after.

We have continuation behavior for Python already here:

// continue comments
{
beforeText: /^\s*#.*/,
afterText: /.+$/,
action: {
indentAction: IndentAction.None,
appendText: '# ',
},
},

It is slightly different than what we've chosen for R; it will continue in the middle of a comment but not at the end. We inherit this behavior from upstream, while the R behavior was chosen to be more like RStudio. It's a little weird that the behavior is different but maybe appropriate, for the two language communities?

Release Notes

New Features

  • Added continuation for regular comments for R

Bug Fixes

  • N/A

QA Notes

The comment continuation for roxygen (#') and plumber (#*) should continue to work in .R files in R Quarto cells, and now we will additionally continue regular old comments (#) in the same spots.

Copy link

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

@juliasilge juliasilge marked this pull request as ready for review January 18, 2025 01:02
@juliasilge juliasilge requested a review from jennybc January 18, 2025 01:03
@lionel-
Copy link
Contributor

lionel- commented Jan 21, 2025

It is slightly different than what we've chosen for R; it will continue in the middle of a comment but not at the end. We inherit this behavior from upstream, while the R behavior was chosen to be more like RStudio

I would expect R to behave like the Python behaviour you describe.

In Zed comments are continued after pressing enter at the end of the line by default, and it's quite unexpected to me every time, as well as annoying. IIRC @DavisVaughan feels the same. At least the behaviour is configurable via extend_comment_on_newline.

It's also worth considering that once we have a stronger story for refilling / word-wrapping comments (e.g. via air formatting) hitting enter at the end of the line to continue a comment will not be a necessary or recommended workflow since manual wrapping is often wrong.

@DavisVaughan
Copy link
Contributor

DavisVaughan commented Jan 21, 2025

To be super clear is this continuing comments that aren't "in the middle"? For example, if we hit enter at the cursor do we get a continued comment now?

# comment<cursor>
1 + 1

Or do we only get a continued comment after an Enter press here, "in the middle" of two comments?

# comment1<cursor>
# comment2

I believe I would greatly dislike if the first example continued a comment.

@juliasilge
Copy link
Contributor Author

I just dug into this a little bit more:

  • RStudio continues comments for roxygen and plumber by default but only does so for regular # comments when users opt in via a setting; this is probably why we didn't originally add this behavior. I think it's fine for us to do this by default.
  • RStudio does in fact continue comments at the end of a comment for roxygen, plumber, and regular comments (after opting in). It's interesting that both @DavisVaughan and @lionel- are saying they think this isn't great, given that it's how RStudio works. 🤔

@DavisVaughan
Copy link
Contributor

given that it's how RStudio works

Yea but only if you opt in to this setting that enables it for regular comments, which I (and presumably most RStudio users) have never done

@juliasilge
Copy link
Contributor Author

Have either of you ever noticed the behavior for roxygen comments and/or plumber comments?

@DavisVaughan
Copy link
Contributor

Yes I appreciate the trailing continuation comment for roxygen comments because I am generally writing a big block of doc comments at once, so continuation almost always makes sense there

But with normal R comments I'd say the 90% case is that my comment spans a single line, so when I hit enter after it I typically like to get out of comment mode

@DavisVaughan
Copy link
Contributor

I feel like it is pretty typical of programming languages for doc comments to have continuation behavior, but normal comments don't. Rust does this, for example. /// comments have continuation but // dont

@juliasilge
Copy link
Contributor Author

I just did a bit more research and I don't believe we can put onEnterRules behind configuration. We can either add this for regular comments or not; it would be tough to make it opt-in like RStudio.

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.

3 participants